View Single Post
Old Jun 20th, 2006, 1:19 PM   #3
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
Finished

I spent some time on the code today and got it working exactly like i wanted. Bassically, it checks to see what processes are running, counts them, and if Notepad isn't running, it fires it up. Lemme know what you think. I can handel honestly regardless of how brutal.
' VBScript source code
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process",,48)

'Going to cycle through all process running and incrementing. 
'If notepad is found in running process, it'll updated "NoteRun" var w/ a numeric
'Put a 0 in the NoteRun var
		NoteRun = 0	
For Each objItem in colItems
			
		'Checks to see if notepad is in the list of running processes.
		if objItem.Caption = "notepad.exe" then
			NoteRun = 1
		else 
			AppVar = AppVar + 1
		end if
Next

AppVar = AppVar + NoteRun
'Wscript.echo "You have " & appvar & " applications running! You have " & NoteRun & " notepad instances running!" 

'Checks NoteRun var to see if it's running. 
if NoteRun = 0 then
	strComputer = "."
	Hidden_Window=5
	Set objWMIService = GetObject ("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	set objStartup = objWMIService.Get("Win32_ProcessStartup") 
	Set objConfig = objStartup.SpawnInstance_ 
	bjConfig.ShowWindow = Hidden_Window
	Set objProcess = GetObject ("winmgmts:root\cimv2:Win32_Process")
	errReturn = objProcess.Create("notepad.exe", null, objConfig, intProcessID)
	WScript.echo "Notepad was not running, but it is now!"
end if

Also, do i have to have a certian amount of posts before I can modify my own posts / headers?

-marshall
__________________
_Marshall_

"America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt."
randum77 is offline   Reply With Quote