We help IT Professionals succeed at work.

Asp.Net State Service Batch File

slb2008
slb2008 asked
on
Dear experts-exchange,

I would like to know how to create a batch file for the ASP.NET State Service, since I don’t want to login to a remote server, to go the administrative tools, services and later re-start the asp.net state service all the time .   That’s a long way to navigate to another server.  I want to have a shortcut batch file in my local pc, so if ASP.net State Service stops, I just click the shortcut and the asp.net state service will re-start without go to another server.  Your assistance and help is appreciated.

Sample batch file like this:

Path remote server ?
net stop "ASP.NET State Service"
net start "ASP.NET State Service"
sc config ?????  start= auto

Thanks.
Comment
Watch Question

Ted BouskillSenior Software Developer
Top Expert 2009

Commented:
You need to use PowerShell.  It's free from Microsoft and built into Windows 2008 or Windows 7 but has to be installed in older operating systems.  Search the web for PowerShell script sites.  There are LOTS
Full stack Software Engineer
Commented:
run the following script to restart asp.net state service (SERVER_NAME).
make sure to change server name at the top of the script.
const SERVER_NAME = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & SERVER_NAME & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")

StopService
'WaitStartStopService false
Wscript.Echo "Service was stopped..."
WScript.Sleep 5000
StartService
'WaitStartStopService true
Wscript.Echo "Service was started..."


Sub StopService
	errReturn = objProcess.Create("net stop ""ASP.NET State Service""", null, null, intProcessID)

	If errReturn = 0 Then
		Wscript.Echo "net stop ASP.NET State Service is processed: " & intProcessID
	Else
		Wscript.Echo "net stop ASP.NET State Service could not be processed due to error: " & errReturn
	End If
End Sub 

Sub StartService
	errReturn = objProcess.Create("net start ""ASP.NET State Service""", null, null, intProcessID)

	If errReturn = 0 Then
		Wscript.Echo "net start ASP.NET State Service is processed: " & intProcessID
	Else
		Wscript.Echo "net start ASP.NET State Service could not be processed due to error: " & errReturn
	End If
End Sub

Open in new window

Meir RivkinFull stack Software Engineer

Commented:
then goto your desktop and create shortcut file.
in the path add the following:

C:\Windows\System32\cscript.exe <script_location>
Meir RivkinFull stack Software Engineer

Commented:
shortcut properties...
shortcut.jpg

Author

Commented:
Thanks sedgwick for the script and shortcut properties, but where I will insert your script?  Do I need to create a new vb.net file?

Author

Commented:
tedbilly,
 
Thanks for your comment. I am familiar with PowerShel, but I don't use the PowerShell very much.  I'll check for the PowerShell scripts. Thanks.

Author

Commented:
sedgwick:
Sorry I didn't reply you sooner, but I can tell you I create vbs script file using notepad and save the file as remote_proc.vbs on c:\vbs folder and later I created a new shortcut.  Your script and RemoteRestart Properties worked really well.  After created the shortcut on the desktop I clicked it from my machine with good results, so I don't need to login to another server to restart the asp.net service.  Thanks for your help. I appreciated it and you will get 500 points.
slb2008