Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exiting a script

Status
Not open for further replies.

DantanaSwat

IS-IT--Management
Dec 3, 2003
29
US
I was tasked to set up login popup screens to happen every 2 weeks or so and log a response. If it were just one message...then no problem...but they wanted 2 weeks, harasment, 2 weeks, e-mail, 2 weeks computer usage and then back to the start. I wrote a script that logged the yes and then when the log file got older than 2 weeks it read the last line..in InStr x then run y, if y then run z yada yada..long stry short I got that part set up. However...I now need to find out how to exit the script and not to run if its a terminal services logon. There are alot of WMI I can use to find out if its a term serv login but this is an NT box. I ultimatly found out that if I use the WSH Environment...and query processes instead of system...that the term serv session has a WINSTATIONNAME variable...now the question is...how do I exit the entire script if this variable is there? I cant find anywhere that will let me
kill the script.

here is the message box part

const forReading = 1

set WSHNetwork = WScript.CreateObject("WScript.Network")
set WSHShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
strUser = WSHNetwork.UserName
strComputer = WSHNetwork.ComputerName
strFolder = "x:\logins\" & strUser
strFile = strFolder & "\" & strComputer & ".txt"
strNo = strFolder & "\" & "userNo.txt"

'drive mapping
WSHNetwork.MapNetworkDrive "S:", "\\someserver\eia"
WSHNetwork.MapNetworkDrive "x:", "\\PDC\netlogon"

'net time
WSHShell.Run "net time \\timeserver /set /y"

'check if folder exists...if not then create it and the txt file
If objFSO.FolderExists(strFolder) Then
set objFile = objFSO.GetFile(strFile)
else objFSO.CreateFolder(strFolder)
objFSO.CreateTextFile(strFile)
set objFile = objFSO.GetFile(strFile)
end If

'should be created and file should be 'gotten' for date check
if datediff("d", Now, objFile.DateLastModified) > 14 Then
WScript.Echo objFile.DateLastModified
readfile
end if

'msgBox functions
function msgHarass(ByVal strFile)
response = MsgBox("I am harassing you ", 4164, "Good Example")
if response = 7 then
logoff(strNo)
else
set objFile = objFSO.OpenTextFile(strFile, 8)
objFile.WriteLine(strUser & "," & now & "," & strComputer & "," &"Harass" & "," & "Yes")
objFile.Close
end if
End Function

sub msgEMail(ByVal strFile)
response = MsgBox("This is for e-mail ", 4164, "E-Mail Example")
if response = 7 then
logoff(strNo)
else
set objFile = objFSO.OpenTextFile(strFile, 8)
objFile.WriteLine( strUser & "," & now & "," & strComputer & "," & "Email" & "," & "Yes")
objFile.Close
end if
End sub

function msgUsage(ByVal strFile)
response = MsgBox("Use your system smartly", 4164, "User")
if response = 7 then
logoff(strNo)
else
set objFile = objFSO.OpenTextFile(strFile, 8)
objFile.WriteLine(strUser & "," & now & "," & strComputer & "," & "Usage" & "," & "Yes")
objFile.Close
end if
End Function

'logoff function
function logoff(noFile)
If objFSO.FileExists(noFile) Then
set objFile = objFSO.OpenTextFile(noFile,8)
else objFSO.CreateTextFile(noFile)
set objFile = objFSO.OpenTextFile(noFile, 8)
end If
objFile.WriteLine(strUser & "," & strComputer & "No")
objFile.Close

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(4)
Next
end function


'function to read logfile and send to appropriate function
function readfile
set objFile = objFSO.OpenTextFile(strFile, 1)
Do until objFile.AtEndOfStream
strLine = objfile.ReadLine
Loop
if InStr(strLine, "Usage") Then
msgHarass(strFile)
elseif InStr(strLine, "Harass") Then
msgEmail(strFile)
elseIf InStr(strLine, "Email") Then
msgUsage(strFile)
Else
msgUsage(strFile)
End if
End function

'unmap drives
WSHNetwork.RemoveNetworkDrive("x:")

and here is the part ill add to find the winstationname

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("PROCESS")
For Each obj In WshSysEnv
If InStr(obj, "WINSTATIONNAME") Then
somehow Exit the script
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top