Pages

Thursday 23 July 2009

Set Working Directory of Shortcut

Set objShell = WScript.CreateObject("WScript.Shell")
Set objShtCut = objShell.Createshortcut("D:\Documents and Settings\All Users\Start Menu\Programs\MKS Toolkit\Evaluation Guide\For Systems Administrators\Desktop Shortcuts.lnk")
objShtCut.WorkingDirectory = "C:\PROGRA~1\MKSTOO~1\Demonstrations\bin"
objShtCut.Save
'WScript.Echo objShtCut.WorkingDirectory

Stop and Delete Service - VBScript

Option Explicit
On Error Resume Next


Dim objWshShell
Set objWshShell = CreateObject("WScript.Shell")


objWshShell.Run "sc stop Nicelog",0,true
objWshShell.Run "sc delete Nicelog",0,true


Set objWshShell = Nothing

Add Registry of Type REG_NONE - VBScript

Dim objWshShell


Set objWshShell=CreateObject("WScript.Shell")


WINDIR =objWshShell.ExpandEnvironmentStrings("%windir%")
objWshShell.Run "reg add HKCU\Software\Google\Google /v hello /t REG_NONE",0


Set objWshShell=Nothing

Create Binary Registry - VBSCript

const HKEY_CURRENT_USER = &H80000001
strKeyPath = "Software\Google\Google Earth Plus"
strComputer = "."
iValues = Array()
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
BinaryValueName = "FailureActions"
oReg.SetBinaryValue HKEY_CURRENT_USER,strKeyPath, BinaryValueName,iValues

Creating STRING and DWORD Values - VBScript

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut


Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")


strKeyPath = "SOFTWARE\System Admin Scripting Guide"
strValueName = "String Value Name"
strValue = "string value"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strValueName = "DWORD Value Name"
dwValue = 82
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

Check Service - VBScript

On Error resume next
Dim StrComputer: strComputer = "."
Dim oservice
Dim oWMIService : Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Dim colServiceList: Set colServiceList = oWMIService.ExecQuery("Select * from Win32_Service where Name='SharedAccess'")


For Each oService in colServiceList


if oService.startmode="Manual" or oService.startmode="Disabled" then
wscript.quit(1)
end if


if oservice.State="Stopped" then
wscript.quit(1)
end if


Next

Stop and Start Service - VBScript

Option Explicit
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, strService, intSleep
strComputer = "."
intSleep = 15000
WScript.Echo " Click OK, then wait " & intSleep & " milliseconds"


'On Error Resume Next
'NB strService is case sensitive


strService = " 'Alerter' "
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ="_
& strService & " ")
For Each objService in colListOfServices
objService.StopService()
WSCript.Sleep intSleep
objService.StartService()
Next
WScript.Echo "Your "& strService & " service has Started"
WScript.Quit
' End of Example WMI script to Start / Stop services