BreadCrumbs: Visual Basic Script

Visual Basic Script

From Luke Jackson

(Difference between revisions)
Jump to: navigation, search
Revision as of 03:45, 7 November 2010 (edit)
Ljackson (Talk | contribs)
(Onyx Registration Script)
← Previous diff
Revision as of 05:35, 7 November 2010 (edit)
Ljackson (Talk | contribs)
(Onyx Registration Script)
Next diff →
Line 24: Line 24:
Select Case LCase(Process.Name) Select Case LCase(Process.Name)
Case "postershop.exe" 'Onyx ProductionHouse Case "postershop.exe" 'Onyx ProductionHouse
- retCode = oWSHShell.Popup(Process.Name & " will Close in 30 seconds.", 30, "Onyx Registration Script", 4 + 16) + 'retCode = oWSHShell.Popup(Process.Name & " will Close in 30 seconds.", 30, "Onyx Registration Script", 4 + 16)
- Select Case retCode+ 'Select Case retCode
- case 6, -1+ 'case 6, -1
- Process.Terminate(0) 'Yes or timeout was chosen+ 'Process.Terminate(0) 'Yes or timeout was chosen
- case 7+ 'case 7
- WScript.quit(1) 'No was chosen+ 'WScript.quit(1) 'No was chosen
- End Select+ 'End Select
 + Process.Terminate(0)
End Select End Select
Next Next
Line 41: Line 42:
WScript.Sleep 20000 'Wait 20 seconds. WScript.Sleep 20000 'Wait 20 seconds.
- oWSHShell.Run """E:\Onyx Graphics\ProductionHouse\server\Postershop.exe""", 8, False+ oWSHShell.Run """E:\Onyx Graphics\ProductionHouse\server\Postershop.exe""", 5, False
WScript.Sleep 30000 'Wait 30 seconds. WScript.Sleep 30000 'Wait 30 seconds.
- Set isAlive = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Postershop.exe'")+ oWSHShell.AppActivate "Enter"
- If isAlive.Count = 1 Then+ WScript.Sleep 5000 'Wait 5 seconds.
 + oWSHShell.SendKeys "{TAB}{ENTER}" 'Close the registration screen.
- Set Processes = objWMIService.InstancesOf("Win32_Process")+ 'oWSHShell.Run "C:\DD\Scripts\close.register.onyx.vbs", 8, False
- For each Process in Processes +
- Select Case LCase(Process.Name) +
- Case "postershop.exe" 'Onyx ProductionHouse+
- oWSHShell.AppActivate Process.ProcessId+
- oWSHShell.SendKeys "{TAB}{ENTER}" 'Close the registration screen.+
- End Select +
- Next+
- End If+
Else Else
MsgBox "Onyx is still running. Please close the application and attempt registration again.", vbCritical, "Onyx Registration Script" MsgBox "Onyx is still running. Please close the application and attempt registration again.", vbCritical, "Onyx Registration Script"

Revision as of 05:35, 7 November 2010

Onyx Registration Script

Dim oWSHShell
Dim oWSHEnvironment
Dim Processes
Dim Process
Dim isAlive
Dim retCode
Dim RegItm1
Dim RegItm2
Dim CurApp

Set oWSHShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:")
Set Processes = objWMIService.InstancesOf("Win32_Process")
'Set oWSHEnvironment = oWSHShell.Environment("windir")
RegItm1 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProductKey"
RegItm2 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\ProductKey"

For each Process in Processes  
	'WScript.Echo Process.Name
	'WScript.Echo Process.ProcessId
	Select Case LCase(Process.Name)  
		Case "postershop.exe" 'Onyx ProductionHouse
        		'retCode = oWSHShell.Popup(Process.Name & " will Close in 30 seconds.", 30, "Onyx Registration Script", 4 + 16)		
			'Select Case retCode
        			'case 6, -1
                			'Process.Terminate(0) 'Yes or timeout was chosen
        			'case 7
                			'WScript.quit(1) 'No was chosen
			'End Select
			Process.Terminate(0)
	End Select    
Next

Set isAlive = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Postershop.exe'")

If isAlive.Count = 0 Then
	If keyExists(RegItm1) = True Then oWSHShell.RegDelete RegItm1
	If keyExists(RegItm2) = True Then oWSHShell.RegDelete RegItm2
	WScript.Sleep 20000 'Wait 20 seconds.

	oWSHShell.Run """E:\Onyx Graphics\ProductionHouse\server\Postershop.exe""", 5, False
	WScript.Sleep 30000 'Wait 30 seconds.

	oWSHShell.AppActivate "Enter"
	WScript.Sleep 5000 'Wait 5 seconds.
	oWSHShell.SendKeys "{TAB}{ENTER}" 'Close the registration screen.

	'oWSHShell.Run "C:\DD\Scripts\close.register.onyx.vbs", 8, False
Else
	MsgBox "Onyx is still running. Please close the application and attempt registration again.", vbCritical, "Onyx Registration Script"
	Set oWSHShell = Nothing
	WScript.Quit
End If

Set oWSHShell = Nothing
WScript.Quit

'Start Functions

function KeyExists(byval sKeyPath)
    keyExists= false
    sKeyPath= trim(sKeyPath): if (sKeyPath="") then exit function
    if not (right(sKeyPath, 1)="\") then sKeyPath= sKeyPath & "\"

    on error resume next
        createobject("wscript.shell").regRead sKeyPath

        select case err
           case 0: keyExists= true

           case &h80070002: dim sErrMsg
               sErrMsg= replace(err.description, sKeyPath, "")
               err.clear

               createobject("wscript.shell").regRead "HKEY_ERROR\"
               keyExists= not (sErrMsg=replace(err.description, _
                  "HKEY_ERROR\", ""))
        end select
    on error goto 0
end function
Personal tools