Run .bat file from ASP.net to restart print spooler

hi all

i write a small batch file (.bat) contains two line to restart the Print spooler service
net stop "Print spooler"
net start "Print Spooler"

Open in new window


and from my asp.net page once i click on a button im running this code:
dim myprocess as new system.diagonastics.process
myprocess .startinfo=new processStartInfo("path to bat file")
myprocess.Start()
myprocess .Close()

Open in new window


when i run this and debug it it run fine without any error but actually the print spooler is not affected at all
LVL 16
Kamal KhaleefaInformation Security SpecialistAsked:
Who is Participating?
 
Kamal KhaleefaInformation Security SpecialistAuthor Commented:
HI EE

i found an alternative solution for this to avoid all security issues

from our asp.net application ,i add a button with name restart Printers

once u click this button i will add a value to a table in the database

then i create an exe file and add it to task schedule that check the database
and if there is a value it will run the bat file from the exe
0
 
käµfm³d 👽Commented:
Does the user that is running you app pool have rights to run the net command?
0
 
Kamal KhaleefaInformation Security SpecialistAuthor Commented:
the application pool has full control over the file
0
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

 
käµfm³d 👽Commented:
I'm not asking about the file, I'm asking about the net command.
0
 
Kamal KhaleefaInformation Security SpecialistAuthor Commented:
How i can check that?
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
In default configs, only Power Users and Administrators are allowed to control services. So check if the App Pool owner is in one of those groups - but be aware that this allows for many other things, too, and is a severe security vulnerability!

It is better to just assign privileges to restart this specific service. You can do that with e.g. subinacl or ntrights, both need to be downloaded first (part of the Windows Resource Kits). I'll show for subinacl (see http://support.microsoft.com/kb/288129 for reference):
subinacl /service "Print Spooler" /grant=DomainOrPC\AppPoolUser=TOI

Open in new window

This needs to be executed as admin, and assigns start/stop/query privilege for the spooler service only.
0
 
Kamal KhaleefaInformation Security SpecialistAuthor Commented:
this is was the solution that worked for me to avoid all security issues

thanks for all
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.