Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start service on user logon script

Status
Not open for further replies.

vestlink

Technical User
Mar 11, 2005
13
NO
Hi.

i'm looking for a logon script when a specific user logs on to a computer.

The script should look in the services to see if a service is running (e.g. jboss). I the service is not running it should be started. Would it also be possible to monitor the specific service as in ( but with the difference that a notification should be flashed somehow (balloontip?).

Also a logoff script shutting down the service when the user logs off would be nice.

Hope you can help

Nicolai
 
I thought I was going to let this one go but here's a good start

Code:
strComputer = "."
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
user = wshNetwork.username
Set objShell = CreateObject("WScript.Shell")
wscript.echo user

If User = "Username" then
   Call isStopped
else
   wscript.quit
end if

Sub  isStopped
 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
   Set colRunningServices =  objWMIService.ExecQuery ("Select * from Win32_Service Where Name = 'MDM'")
   For Each objItem In colRunningServices
   If objItem.State="Stopped" Then 
       wscript.Echo "MDM STOPPED" & objItem.DisplayName & " -- " & objItem.State
	   Call SetManStart
   Else
       wscript.echo "MDM RUNNING" & space(1) & objItem.DisplayName & " -- " & objItem.State 
	End If
   Next
End Sub

Sub SetManStart
'Set service to Manual
Set objWMIService = GetObject("winmgmts:" _ 
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set colServicesState = objWMIService.ExecQuery _ 
  ("Select * from Win32_Service where Name='MDM'") 
For Each objService in colServicesState 
	objService.ChangeStartMode("AUTO")
	wscript.sleep 5000
'Start service
If objService.State="Stopped" then 
 objService.StartService()
	wscript.sleep 2000
	wscript.echo "Started"
End If
Next
End Sub
 
Hi again.

This worked great. I think i'll try to disable the initial feedback so that the user doesn't have to verify. But what lines must be omitted/commented-out?

I used MMC and added the script via Group Policy Object.

Nicolai
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top