richardrekos
MIS
I am trying to use an If statement for the first time. I want to run a Sub based on if the user clicks OK or Cancel.
The Sub "rich" runs regardless of whether I click OK or Cancel. What am I doing wrong?? Also, is there a way to go back to and start the script over after the Sub "rich" is called? Many Thanks in advance!
Const intCancel = 2
Const intOK = 1
strComputer = InputBox("Enter computer name and click ok. If you don't know the name of your computer, click cancel")
If intCancel Then
call rich()
Else
If intOK Then
call rich2()
End IF
End IF
Sub rich()
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
Wscript.Echo "Name: " & objItem.Name
Next
End Sub
Sub rich2()
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "c:\Assettracker\clientcon.exe"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "richard.rekos@questionmark.com"
objEmail.To = "richard.rekos@questionmark.com"
objEmail.Subject = "AT Output"
objEmail.Textbody = "AT Output"
objEmail.AddAttachment "C:\assettracker\data\" & strComputer & ".xml"
objEmail.Send
End Sub
The Sub "rich" runs regardless of whether I click OK or Cancel. What am I doing wrong?? Also, is there a way to go back to and start the script over after the Sub "rich" is called? Many Thanks in advance!
Const intCancel = 2
Const intOK = 1
strComputer = InputBox("Enter computer name and click ok. If you don't know the name of your computer, click cancel")
If intCancel Then
call rich()
Else
If intOK Then
call rich2()
End IF
End IF
Sub rich()
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
Wscript.Echo "Name: " & objItem.Name
Next
End Sub
Sub rich2()
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "c:\Assettracker\clientcon.exe"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "richard.rekos@questionmark.com"
objEmail.To = "richard.rekos@questionmark.com"
objEmail.Subject = "AT Output"
objEmail.Textbody = "AT Output"
objEmail.AddAttachment "C:\assettracker\data\" & strComputer & ".xml"
objEmail.Send
End Sub