Shortcut for user to run a service as admin - print spooler

Bronze Contributor

Hi all,

 

I need to create a shortcut or something that allows the logged on user to restart the print spooler as admin is this possible? 

 

 

18 Replies
Not sure if that would be a wise decision because it has security implications... Is this trying to fix an issue as a work-around?
Yes, so we have a few staff literally only a few that send something to print but doesnt go through.
We then have to restart the print spooler everytime this issue occurs.

We are awaiting a fix from papercut but till then i wanted to give a workaround for those who are experiencing this issue.
I created a blog a while ago when it was still necessary some times to restart the ime service to trigger some stuff
Can be used for the spooler service though..

https://call4cloud.nl/2020/11/the-non-admin-user-the-battle-of-restarting-services/
Hi Rudy thanks for this.

Due to the print spooler requires another service to also restart would the powershell that I convert into a exe look like this:

net start Print Spooler
net stop Print Spooler
net stop PaperCut Direct Print Monitor
Net start PaperCut Direct Print Monitor

Should be no problem... just add it to the script.

Hi @Rudy_Ooms_MVP 

 

I have got most pieces done except the install and uninstall cmd: 

 

Screenshot 2022-03-21 at 9.49.27 AM.png

 

Also when creating the intune file what do I point it too? 

the install cmd just point to the ps.1 file to launch powershell.. but you could also skip that install.cmd and just use the ps1 in intune so you could use that file as setup file for the app creation.
Hi Rudy,

So for install and uninstall commands on intune could I use: powershell -ex bypass -file Windows10_Restartservice.ps1

Hi @Rudy_Ooms_MVP 

 

So I have packaged the ps1 as the set up file and put the install/uninstall command on intune as: powershell -ex bypass -file Windows10_Restartservice.ps1

 

This deploys to the device and a shortcut is created (Which doesnt link to anything) but the content within the folder 'restartservice' doesn't seem to be pushed to the devices within the folder that is created via the script. 

 

Screenshot 2022-03-23 at 1.23.23 PM.pngScreenshot 2022-03-23 at 1.24.04 PM.png

 

Please help!

HI, Could you check if those files are even in the intunewin file (google extract intunwin tool)
Hi Rudy,
I have now used the extract tool and can confirm the files within the intunewin are the ones I need. however I have noticed something I didnt change in the script used! I will change this and try again / let you know!

Hi @Rudy_Ooms_MVP 

 

So I have managed to get the files to appear but with the bat file itself I have noticed an issue. 

 

When I use: 

net stop Spooler
net start Spooler
net stop PCPrintProvider
net start PCPrintProvider

 

in a bat this doesnt work even when I run as admin. However when I copy this into a cmd window this works fine. Im assuming I need some extra code within the Bat to allow this to run without issues before creating the exe as that also didnt work when I run as admin. 

 

Any ideas on what I need to add to get the bat file to work correctly? 

 

Thanks in advance!

 

 

Hi @Rudy_Ooms_MVP 

 

So I have managed to get the .BAT to work but as there are two services within my BAT file that depend on each other I get the following question which requires a y or n to be inputted. 

 

Capture.PNG

 

How do I prepopulate a Y so it bypasses this question within the Bat file? 

net stop servicename /y
Hi, you could use stop-service -force in powershell and cmd net stop /y

Hi Both @Harm_Veenstra @Rudy_Ooms_MVP 

 

So net stop servicename /yes worked and tested to make sure I also converted this into a exe which then test and worked too! BUT  when I package all the files and deploy via intune the shortcut create nor the exe that worked prior to packaging stops working! Why would this be and how do I get it to work? 

 

My powershell script I used on set up to create the intunewin file:

 

#install and import module
install-packageprovider -name nuget -minimumversion 2.8.5.201 -force | out-null
Install-Module -Name 'Carbon' -AllowClobber -force | out-null
Import-Module 'Carbon'

#grant permission and restart service to take affect
Grant-ServicePermission -Name Spooler -Identity Everyone -QueryStatus -EnumerateDependents -Start -Stop
Grant-ServicePermission -Name PCPrintProvider -Identity Everyone -QueryStatus -EnumerateDependents -Start -Stop

md "c:\program files (x86)\restartservice"
copy .\restartprint.exe "c:\program files (x86)\restartservice\restartprint.exe"
copy .\PaperCut.ico "c:\program files (x86)\restartservice\PaperCut.ico"

#Create Shortcut Desktops
if (-not (Test-Path "C:\Users\Public\Desktop\Restart-Service.url"))
{
$null = $WshShell = New-Object -comObject WScript.Shell
$path = "C:\Users\Public\Desktop\Restart-Service.url"
$targetpath = "c:\program files (x86)\restartservice\restartprint.exe"
$iconlocation = "c:\program files (x86)\restartservice\PaperCut.ico"
$iconfile = "IconFile=" + $iconlocation
$Shortcut = $WshShell.CreateShortcut($path)
$Shortcut.TargetPath = $targetpath
$Shortcut.Save()

Add-Content $path "HotKey=0"
Add-Content $path "$iconfile"
Add-Content $path "IconIndex=0"
}

 

Hi,
So the exe is been placed in the restartservice folder like expected? or is it missing from that folder?
If that's not the case, maybe changing the md and copy lines to :
New-Item -Path "c:\" -Name "test" -ItemType "directory"
Copy-Item -Path ".\*" -Destination "c:\test\" -Recurse

So you could also rule out the sysnative x86 issue
Of course you will need to also change the shortcut lines
The correct exe goes into the correct folder.

The issue is that it doesnt run correctly - the service doesnt get restarted however before packaging the exe and sending it via intune the exe worked perfectly on a local device when testing