TIPS: WMI: VBScript: Start a process with different priority


dim intProcessID
Const HIGH = 128
strComputer = “.”

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2:Win32_Process”)
Set objStartup = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2:Win32_ProcessStartup”)
objStartup.PriorityClass = HIGH          !!!!! ‘ Here you can define the priority of the process. !!!!!!
Set objConfig = objStartup.SpawnInstance_
objWMIService.Create( sCommand, sWorkingDir, objConfig, intProcessID)

Advertisements

TIPS: VBScript : Get Logged in username using VBScript.


  • Using Environment Variable

Set wshShell = WScript.CreateObject( “WScript.Shell” )
strUserName = wshShell.ExpandEnvironmentStrings( “%USERNAME%” )
WScript.Echo “User Name: ” & strUserName

  • Using WshNetwork

Set wshNetwork = WScript.CreateObject( “WScript.Network” )
strUserName = wshNetwork.UserName
WScript.Echo “User Name: ” & strUserName

  • Using ADSI (ADSystemInfo)

Set objSysInfo = CreateObject( “ADSystemInfo” )
strUserName = objSysInfo.UserName
WScript.Echo “User Name: ” & strUserName

  • ADSI (WinNTSystemInfo)

Set objSysInfo = CreateObject( “WinNTSystemInfo” )
strUserName = objSysInfo.UserName
WScript.Echo “User Name: ” & strUserName

  • WMI (Win32_ComputerSystem)

Set objWMI = GetObject( “winmgmts:\\.\root\cimv2” )
Set colItems = objWMI.ExecQuery( “Select * from Win32_ComputerSystem” )
For Each objItem in colItems
strUserName = objItem.UserName
Next

 

Adding file type association using vbScriptvb


fext = "fcz"
prgid = "FCZ File"
des = "FCZ File"
extanm = "c:\Program files\TestApps\AppStart.exe"
Set o = CreateObject("wscript.shell")
o.regwrite "HKCR\." & fext & "\" , prgid , "REG_SZ"
o.regwrite "HKCR\" & prgid & "\" , des , "REG_SZ"
o.regwrite "HKCR\" & prgid & "\DefaultIcon\", extico, "REG_SZ"
o.regwrite "HKCR\" & prgid & "\Shell\","Open"
o.regwrite "HKCR\" & prgid & "\Shell\Open\Command\", extanm & " ""%1""", "REG_SZ"