Indigo
(Fresh Scripter)
2008-10-20 06:44 PM
Client Reboot Script / Sends out Email warnings) Version .6

I am editing this first post, so i can Keep the current version of this script as the first post. \:\)

Version .6 Changes:
------> Auto Reboot is Turned OFF By Default You must Un-Comment that line!!!! (Line 130) <-----------
* I have added a Checking Function to make sure that the config file (RS_Config.ini) does exist. If not it prompts for needed info.
* I have also produced a section of code that will write all imputed data to a perfectly formated RS_Config.ini file.
* Please Note When Filling in the Log & Udfs path.... NO TRAILING \ is needed \:\)
* I also wanted to bring up "For the Email function to work you need to have Bmail"

Version .5 Changes:
* I added the config file portion to this script it will now import all the configuration information from the configfile, and assign it to the correct variables.
Config File Name must be RS_Config.ini, and it must be placed in the location where the script is run from.

 Code:
[CONFIG]
Kixlib=Kix_Lib_Path
Logs=Reboot_Script_Log_Locaion
NoReboot=PC1,PC2,PC3
SkipUsers=User1,User2,User3
EmailServer=Hostname_OF_EmailServer(emailserver)
EmailSuffix=Email_Suffix_(company.com)
AdminEmail=IT_Email_Address(it@comapny.com)


* I have also put some color into the output display just for Giggles..:)

Version .4 Changes:
* I made the script more agressive, and it now reboots any system not logged into over the 7 day marker.

Version .3 Changes:
* I have corrected a bug that wouldn't check (User Not Logged In) and send a net message to X machine.
* Glenn helped me correct the issue with the editing out the Domain\ out of the Domain\username.
* I have also fixed the Net Send Message now. It works as intended.. Sends a net message to every user in the Userstoskip array. Reason for the net send is we have some generic users that don't apply to anyones email address, This will send the net send reboot alert message, so these systems arn't skipped from being notified.

Future Code Changes:

* Pull email address without depending on the user being logged in to send the email.
* I would like to have this program to learn how to link systems with users, but this falls under not having a better way to configure how emails are being calcualted and sent out. (Wink Wink...)

Ok thats it for now.

 Code:
; ===========================================================================================
;
;	Title:   Windows XP Reboot of network clients
;	Author:  Indigo			
;	Description:  Sends out emails at 7 Days, and Reboots at 10	
;	Version: .6
;
;	Special Thanks: Glenn, I wanted to say thanks for all the Key help when needed to overcome some hurdles in getting this script this far.
;
;	Revision Notes:
;{Version .6} ------> Auto Reboot is Turned OFF By Default You must Un-Comment that line!!!!  (Line 130) <-----------
;	* I have added a Checking Function to make sure that the config file (RS_Config.ini) does exist.  If not it prompts for needed info.
;	* I have also produced a section of code that will write all imputed data to a perfectly formated RS_Config.ini file.
;	* Please Note When Filling in the Log & Udfs path.... NO TRAILING \ is needed :)
;	* I also wanted to bring up "For the Email function to work you need to have Bmail"
;{Version .5}	
;	* I added the Ability to read from a config file.  The config file must remain in the location from where the script is called InI file is RS_Config.ini	
;	* I have also added some color to the Current Status Display, and I moved it to its own function.
;	* I also made the Script more agressive when it comes to users that arn't logged in, It will auto reboot those systems instead of sending text message.
;	* Note: the system will still do a Net Send Messages to the current system being proccess for any generic users that are defined in the Users to skip section. 
;
; ===========================================================================================
CLS
; == Seting Kixtart Options == 

$Rc = SetOption('Explicit', 'Off')
$Rc = SetOption('NoVarsInStrings', 'On')
$Rc = SetOption('NoMacrosInStrings', 'On')
$Rc = SetOption('WrapAtEOL', 'On')

Break on

; == Declaring Variables. == 

Dim $DontReboot		; == Systems that won't be rebooted
Dim $UserstoSkip	; == Users that will be skipped
Dim $EmailServer	; == The Hostname of the Email Server
Dim $EmailSufix		; == The "company.com" in the Email addresses
Dim $RS_Logs		; == The Log Location \\server\share\path\
Dim $IT_Email		; == The Administrator Email
Dim $Rc				; == Return Code for Kixtart Options
Dim $Computers		; == An Array that holds all the Computers Comnetview gathers
Dim $Computer		; == Each Compuer in Computers
Dim $Online			; == Systems Online / Not Online
Dim $Winver			; == Windows Version
Dim $WMICheck		; == WmiCheck pass/fail
Dim $Uptime			; == Uptime in Days IE. 10
Dim $Kixlib			; == Kix Library location

$CfgFile = @ScriptDir + "\RS_Config.ini"	; Defines the Script Location.

CheckforConfigFile($CfgFile)

; == Intializing  Computer & User Special Consideration Veriables == ***** Variables below must be changed to needed Values ******

$DontReboot  = Split(ReadProfileString($CfgFile, 'CONFIG', 'NoReboot'), ',')	; Computers to Be Skipped
$Userstoskip = Split(ReadProfileString($CfgFile, 'CONFIG', 'SkipUsers'), ',')	; Users to be Skipped
$EmailServer = ReadProfileString($CfgFile, 'CONFIG', 'EmailServer') 			; HostName of Email Server
$EmailSufix  = ReadProfileString($CfgFile, 'CONFIG', 'EmailSuffix')				; Sufix of Email Address Company.com

$RS_Logs = ReadProfileString($CfgFile, 'CONFIG', 'Logs')				; Don't use the trailing \ because it won't work right
$IT_Email = ReadProfileString($CfgFile, 'CONFIG', 'AdminEmail')			; Email Address of System Admin or Group
$Kixlib = 	ReadProfileString($CfgFile, 'CONFIG', 'Kixlib')				; Define Where your Kixtart Lib is here Do not place a trailing \

; === Includes all Udfs needed for this script ===				 	**********************************************************

 Call $Kixlib + "\Comnetview.udf"
 Call $Kixlib + "\WmiUptime.udf"
 Call $Kixlib + "\Translatename.udf"
 Call $Kixlib + "\Ping.udf"
 Call $Kixlib + "\FnWMIloggedin.udf"
 Call $Kixlib + "\WMIConfirm.udf"

; == Clears Log Files If Script has been run before == 		   

del $RS_Logs + "\Systems_UpTime.txt"							
del $RS_Logs + "\Systems_Offline.txt"		

$computers = COMNetView()			; == Locates computers on the network 
CLS
For Each $computer in $computers											
	$online = Ping($computer,0,0,1)	; == Ping confirms computer online
	If $online = "1"														
		$winver = ReadValue("\\" + $computer + "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductName")
		If $winver = "Microsoft Windows XP" 								
			$WMICheck = WMIConfirm($computer)
				If $WMICheck <> 0										
					$UpTime = WMIuptime($computer)
					$Userloggedin = GetloginName($Computer)	
					
					
					DisplayInfo($Computer,$Winver,$Userloggedin,$Uptime); == This Function displays the current system info
					
					
					If len(ltrim($Uptime[0])) <> 0						; == Checks digit value of Uptime to see if it is 0 or not
						If Systemcheck($Computer,$DontReboot) = -1		; == Checks to make sure system isn't in the Protected list
							
							If $Uptime[0] >= 7
								If RedirectOutput ($RS_Logs + "\Systems_UpTime.txt") = 0 
									$Userloggedin = GetloginName($computer)	
									? $computer + "'s Uptime is: " + $Uptime[0] + " Days.  " + $Userloggedin ?
									$ = RedirectOutput("")
								EndIf 
							EndIf;
					
							Select
								Case $Uptime[0] >= 0 and $Uptime[0] < 7								

									If Exist ($RS_Logs + "\" + $computer + ".SentEmail.txt")
										"Email Tag File found Deleting .... < 7 " + @CRLF
										del $RS_Logs + "\"+ $computer + ".SentEmail.txt"
									Endif
									@CRLF
									
								Case $Uptime[0] >= 7 and $UpTime[0] < 10
									
									If $Userloggedin = "(User Not Logged In)"
										@CRLF + $Computer + " Is being rebooted.. Because no one is logged in." + @CRLF
										Shutdown ($computer, "This System Is Being Rebooted in 3 seconds....",3,1,1)
									Else	
										"System is being processed." + @CRLF
										WriteEmail($computer,$Uptime[0],$RS_Logs)			
										SendEmail($Userloggedin,$Computer,$Uptime[0],$EmailServer,$IT_Email,$EmailSufix,$RS_Logs,$Userstoskip,0)
									EndIf
								
								Case $Uptime[0] >= 10 										
									
									If Exist ($RS_Logs + "\" + $Computer + ".SentEmail.txt")
										@CRLF + $Computer + " Is being rebooted.." + @CRLF
										;Shutdown ($computer, "Please Save Your Work,  This System Is Being Rebooted in 1 min.",60,1,1)
									Else
										WriteEmail($computer,$Uptime[0],$RS_Logs)
										SendEmail($Userloggedin,$Computer,$Uptime[0],$EmailServer,$IT_Email,$EmailSufix,$RS_Logs,$Userstoskip,0)
									Endif
							
							Endselect
						Else
							@CRLF + "This System Is In The Protected List..(Skipping)" + @CRLF
							Sleep 2
						EndIf
					Else
					@CRLF +  "Uptime Check Failed!!! (Skipping & Logging)" + @CRLF + "Logfile: " + $RS_Logs + "\System_UptimeChck_Failed.txt" + @CRLF
						If RedirectOutput ($RS_Logs + "\System_UptimeChck_Failed.txt") = 0 
							"Uptime Check On: " + $computer + " Failed!!" + @CRLF
							$ = RedirectOutput("")
						EndIf
					EndIf
				Else
					$computer + " was skipped & Logged for review. WmiReturn Code: " + $WMICheck + @CRLF
					If RedirectOutput ($RS_Logs + "\Errorlog.txt") = 0 
						$computer + "'s Error Code is " + @error + " - " + @SERROR + @CRLF
						"This system was skipped & Logged for review. WmiReturn Code: " + $WMICheck + @CRLF
						$ = RedirectOutput("")
					EndIf 
				Endif
		EndIf
	Else
		If RedirectOutput ($RS_Logs + "\Systems_Offline.txt") = 0 
			$computer + @CRLF
			$ = RedirectOutput("")
		EndIf
	Endif
Next
; ----- System Reboot Email with attached System Uptimes Log -----
	
	SendEmail($Userloggedin,$Computer,$Uptime[0],$EmailServer,$IT_Email,$EmailSufix,$RS_Logs,$Userstoskip,1)

; ================== Functions Below This Point ====================

; ----- This Function checks for a config file if not there prompts for the info --
Function CheckforConfigFile($_CfgFile)
	CLS
	"Checking For RS_Config.ini...." +@CRLF +@CRLF
	If Exist ($_CfgFile)
		"Config File Found .." + @CRLF + "Loading: " + $_CfgFile + @CRLF
		Sleep 5
		Return
	Else
		"Config File Not Found!! Prompting For Needed Data..." + @CRLF
		Sleep 3
		CLS
		"Please Enter The Location Of Where All Dependent Kix UDFs" + @CRLF
		"Format: C:\logs or \\Server\Share\Path" + @CRLF
		Gets $_Kixlib 					; Lib of Kixtart Udfs 
				
		CLS
		"Please Enter Where You Want To Store The Script Logs" + @CRLF
		"Format: C:\logs or \\Server\Share\Path" + @CRLF
		Gets $_RS_Logs					; Don't use the trailing \ because it won't work right
		
		CLS
		"Please Enter The Systems You Don't Want Rebooted" + @CRLF
		"Format: System,System,System" +@CRLF
		Gets $_DontReboot				; Computers to Be Skipped
	
		CLS
		"Please Enter Users You Don't Want Getting Emails" + @CRLF
		"Format: User,User,User" + @CRLF
		Gets $_Userstoskip				; Users to be Skipped
	
		CLS
		"Please Enter The Hostname Of The Email Server" + @CRLF
		"Format: hostname" + @CRLF
		Gets $_EmailServer				; HostName of Email Server
		
		CLS
		"Please Enter The Email Sufix For Your Companies Email Addresses" + @CRLF
		"Format: company.com" + @CRLF
		Gets $_EmailSuffix   			; Sufix of Email Address Company.com
				
		CLS
		"Please Enter The IT Email Address" + @CRLF
		"Format: it@company.com" + @CRLF
		Gets $_IT_Email 				; Email Address of System Admin or Group
		
		"Writing Config File......" + @CRLF
		If RedirectOutput ($_CfgFile,1) = 0 
			"[CONFIG]" + @CRLF
			"Kixlib=" + $_Kixlib + @CRLF
			"Logs="+ $_RS_Logs + @CRLF
			"NoReboot=" + $_DontReboot + @CRLF
			"SkipUsers=" + $_Userstoskip + @CRLF
			"EmailServer=" + $_EmailServer + @CRLF
			"EmailSuffix="+ $_EmailSuffix + @CRLF
			"AdminEmail=" + $_IT_Email + @CRLF
			$ = RedirectOutput("")
		EndIf 
		Sleep 2
	Endif

EndFunction

; ----- This function displays on the screen the current system information. --
Function DisplayInfo($_Computer,$_Winver,$_Userloggedin,$_Uptime)
	
	CLS
	color m+/n
	"System"color c+/n": " color g+/n  $_Computer color m+/n " ("color c+/n"Online" color m+/n  ")" + @CRLF
	"OS"color c+/n": "color g+/n  $_Winver + @CRLF
	color m+/n
	"User"color c+/n": " color g+/n $_Userloggedin + @CRLF
	color m+/n
	"Uptime"color c+/n": " color g+/n  $_Uptime[0]  color c+/n " Days" + @CRLF color w+/n 

EndFunction

;----- This function just checks to make sure we don't reboot a pc that needs to stay up. --
Function Systemcheck($_Chkcomputer,$_DontReboot)		

; == Declaring Variables
Dim $_Result		; Holds the Result of the calculation
Dim $_Chkcomputer	; Computer to be checked
Dim $_DontReboot 	; Global Variable Transfered to Function.

	$_Result = 0
	$_Chkcomputer = TRIM(LCASE($_Chkcomputer))					
	$_Result = Ascan($_DontReboot,$_Chkcomputer,0)				
	$Systemcheck = $_Result										

EndFunction

; ---- Removes invalid email users ----
Function checkusers($_Users,$_Userstoskip)		

; == Declaring Variables
Dim $_Result		; Holds the Result of the calculation
Dim $_Chkuser		; User to be checked
Dim $_Users			; User passed to function (raw)
Dim $_Userstoskip 	; Global Variable Transfered to Function.

	$_Result = 0
	$_Chkuser = TRIM(LCASE($_Users))					
	$_Result = Ascan($_Userstoskip,$_Chkuser,0)				
	$checkusers = $_Result
	
EndFunction

;----- Pulls in the user that is logged into X machine  ----------------------------
Function GetloginName($_Chkcomputers)

; == Declaring Variables
Dim $_Usrloggedin	; User Logged into current system in current format Domain\Username
Dim $_Usrname		; Just username by itself

$_Usrname = Split(fnWMILoggedIn(1,$_Chkcomputers), '\')[1] ; Extracts the username out of Domain\user to be just User.

If len(ltrim($_Usrname)) = 0	; == Checks for a 0 digit value assigned to user, if it did (User not logged) in is Returned.
	$_Unli = "(User Not Logged In)"
	$Getloginname = $_Unli
	Return
Endif

$Getloginname = $_Usrname

EndFunction


;----- Sends an email to the user whos system has been up for more than 7 days, and sends email to administrator.
Function SendEmail($_User,$_System,$_Systemup,$_EmailServer,$_IT_Email,$_EmailSufix,$_RS_Logs,$_Userstoskip,$_AdminEmail)
; == Declaring Variables
Dim $_User			; User to be emailed
Dim $_System		; Hostname of current system
Dim $_Systemup		; Uptime of Current system
Dim $_Unli			; Defined as (User Not Logged In) - Incase user isn't logged in
Dim $_EmailSufix 	; Global Variable Transfered to Function.
Dim $_IT_Email 		; Global Variable Transfered to Function.
Dim $_RS_log		; Global Variable Transfered to Function.
Dim $_Email			; Building Block Variable for Sending Emails.
Dim $_NetSend		; Building Block of the NetSend Message.
					; Through a Variable for On/Off maybe setup a Debug Admin Feature, so only admin is emailed

$_Email = 'bmail'
$_Email = $_Email + ' -s '
$_Email = $_Email + $_EmailServer
$_Email = $_Email + ' -f ' + $_IT_Email	
	
	If $_AdminEmail = 1
		$_Email = $_Email + ' -t ' + $_IT_Email
		$_Email = $_Email + ' -a ' + '"Systems That need to be rebooted"'
		$_Email = $_Email + ' -m ' + $_RS_Logs + '\Systems_uptime.txt'
	Else
		$_Email = $_Email + ' -t ' + $_User
		$_Email = $_Email + ' -a ' + '"(System Reboot Needed!) Uptime: ' + $_Systemup + ' Days."'
		$_Email = $_Email + ' -m ' + $_RS_Logs + '\' + $_System + '.SentEmail.txt'
	EndIf

$_NetSend = 'net send '
$_NetSend = $_NetSend + $_System
$_NetSend = $_NetSend + ' "Reboot Notice: This system has been turned on for ' 
$_NetSend = $_NetSend + $_Systemup
$_NetSend = $_NetSend + ' days please reboot!, Thanks IT"'


If checkusers($_User,$_Userstoskip) = -1		; Makes sure certian users don't get emails.
	"Sending Email..." + @CRLF
	Shell $_Email
Else
	"Sending Net Send Message..." + @CRLF
	Shell $_NetSend
Endif

EndFunction


;----- Writes the email file that is included in the body of the email sent. ------------
Function WriteEmail($_Computer,$_Uptime,$_RS_Logs)

"Writing Log File.." + @CRLF

; == Declaring Variables
Dim $_Computer 		; Hostname of Current System
Dim $_Uptime		; Uptime of Current System
Dim $_RS_Logs		; Handles Log locations

	If RedirectOutput ($_RS_Logs + "\"+ $_Computer + ".SentEmail.txt",1) = 0  ; == Creates a Log File to indicate the sending of an email.
		@CRLF $_Computer + "'s Uptime is: " + $_Uptime + " Days."	
		@CRLF
		@CRLF "This is the Body of the Email that will be sent... Fill it in with whatever you want."
		@CRLF
		$ = RedirectOutput("")
	EndIf 

EndFunction


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-20 07:21 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Send it to me via PM, I can review it and place it in the Vault.

Add a little background - what/why and the logic you used, so people will understand what you did, why you chose that method, and how it will help them. The vault uses a little different posting style. Doesn't need much.

Glenn


Indigo
(Fresh Scripter)
2008-10-20 09:00 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Alright,

I sent you a PM.

Indigo


LonkeroAdministrator
(KiX Master Guru)
2008-10-20 09:04 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

ofcourse you can always post it in scripts forum...

Indigo
(Fresh Scripter)
2008-10-20 09:08 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Is that ok?

I wasn't sure if I was allowed to do that?


Indigo
(Fresh Scripter)
2008-10-20 09:15 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Reason I Wrote this: (Here is the Basics..) (I am thankful for everyones help in making this script now I want to give back the result of my work.)

We have several users in our network that like to leave their systems on up until it starts doing funky things, and I have learned that it is possible through scripting to do a host of checks and make decisions based on those checks to email users that their systems have been up to long, and reboot those systems where the users are defiant and just won't reboot their systems.

The Script works like this:
1) Pulls a list of systems down from the domain.
2) It Pings the system to make sure its online if not the system is skipped.
3) It then checks to see if the system is "Windows XP" This is a simple way for me to filter out the servers.
4) Then it check the uptime of the current system.
5) It checks to make sure the Uptime returns a Good Value.

Note: I made this script to be able to skip systems that need to be left on.
Note: The Script will also check the users logged in and if not logged in it will send an email to $IT_Email (IT Admins email) to let them know.
Note: I have added in this portion of the code the ability to Do a Net Send message to the computer for when the system is logged into next.

6) Checks the system to make sure its not in the protected list.
7) If the system has been left on for >= 7 days it Creates an email and sends it to the user that was logged into the system being checked.

Note: It will send emails everyday until the system is rebooted.
Note: IF the system has been on less than 7 Days it will delete the Semaphore file created as a marker used on some decisions in the script if it exists.

8) At >= 10 Days it will check to make sure they user has been emailed if not it skips the reboot and sends out a warning email. If the email has been sent it reboots the system.
9) At the End their is a email sent to $IT_Email with the systems that have been on more than 7 days. (For Follow up)

I would like to point out I am not a vet scripter, but I consolidated a few different Udfs and with a dash of my own code I have created a script that I think is very useful.

I also think an easier way to do this (I.e. Just Add to each system a reboot job in the Scheduled Tasks), but that would defeat the purpose of this exersise for me
Also As far as the log files, they may not all be needed... (I have a little more work to do in that area, as well as increasing detail of log files as needed)

This is the very first rendition of this script desinged to use variables instead of hard coding the desired information like log locations, and IT_Email addresses.

I am sure there is many things that can be done to enhance this script beyond my current scripting ability which is part of the reason I would like to offer it up, so I can work on more advanced ideas.

My desire is to have people look at the script, and offer up ideas to add to the script, so the script will be lean, mean, effeciant with some nice features.

I would also like to remove the need to call an external emailing software.

To run the emailing portion of this script you will need the email software called Bmail. It is a command line emailer.

This Script Requies the following UDF Scripts to be Included.
"Script Location" is the location of where your Udfs are placed:

WmiUptime gave me a Blank return on one system, but I adjusted for this, so I created a way to evaluate the Uptime variable and if it had a 0 digit value I discarded the system as failing the WmiUptime check. I am under the impression there is somthing wrong with the system because it is the only one that failes the WmiUptime check.

 Code:
Include "\\Script Location\Comnetview.udf"
Include "\\Script Location\WmiUptime.udf"
Include "\\Script Location\Translatename.udf"
Include "\\Script Location\Ping.udf"
Include "\\Script Location\FnWMIloggedin.udf"
Include "\\Script Location\WMIConfirm.udf"


Below are the configurable Variables for different options in the script:
I think the Variables below are self explanitory.

 Code:
$DontReboot = "Computer Name Here" , "Computer Name Here"
$Userstoskip = "User Name Here","User Name Here"
$EmailServer = "Email Server System Name" ; For email features to work you need Bmail and an open authentication turned on at your email server.
$EmailSufix = "Company.com"

; == Intializing Log File Locations & IT - Email ==

$RS_Logs = "C:" 		    ; Don't use the \ because it won't work right.
$IT_Email = "it@@company.com"       ; Must have Double @@ for it to work right.


NOTE: I TURNED OFF THE SYSTEM REBOOT ACTION INCASE THE SCRIPT IS RUN DURING BUSINESS HOURS.

Review the segment below to locate this section in the code to turn it on.
 Code:
If Exist ("$RS_Logs\$computer.SentEmail.txt")
     ? $computer + " is being rebooted.." + @CRLF
     ;Shutdown ($computer, "Please Save Your Work,  This System Is Being Rebooted in 1 min.",60,1,1)


 Code:
;===========================================================================================
;
;	Title:   Windows XP Reboot of network clients
;	Author:  Indigo			
;	Description:  Sends out emails at 7 Days, and Reboots at 10	
;	Version: .1
;
; ===========================================================================================

BREAK on

; === Calls all Udfs needed for this script ===

Include "\\Script Location\Comnetview.udf"
Include "\\Script Location\WmiUptime.udf"
Include "\\Script Location\Translatename.udf"
Include "\\Script Location\Ping.udf"
Include "\\Script Location\FnWMIloggedin.udf"
Include "\\Script Location\WMIConfirm.udf"

; == Intializing  Computer & User Special Consideration Veriables ==

$DontReboot = "Computer Name Here" , "Computer Name Here"
$Userstoskip = "User Name Here","User Name Here"
$EmailServer = "Email Server System Name" ; For email features to work you need Bmail and an open authentication turned on at your email server.
$EmailSufix = "Company.com"

; == Intializing Log File Locations & IT - Email ==

$RS_Logs = "C:" 					; Don't use the \ because it won't work right.
$IT_Email = "it@@company.com"       ; Must have Double @@ for it to work right.

; == Clears Log Files If Script has been run before == 

del "$RS_Logs\Systems_UpTime.txt"							
del "$RS_Logs\Systems_Offline.txt"		

$computers = COMNetView()			; == Locates computers on the network 

For Each $computer in $computers											
	
	;? "Pinging: " $computer
	$online = Ping($computer,0,0,1)	; == Ping confirms computer online
	If $online = "1"														
		$winver = ReadValue("\\" + $computer + "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductName")
		;? "Reading OS of " $computer " ( " $winver " )"
		If $winver = "Microsoft Windows XP" 								
			$WMICheck = WMIConfirm('$computer')
				If $WMICheck <> 0										
					$UpTime = WMIuptime($computer)
					
					; == Displays Current System Information
					? "System: " + $computer +" (Online)"									
					? "OS: ( " $winver " )"
					? "Uptime: " + $Uptime[0] + " Days"
					; --------------------------------------					
					
					If len(ltrim($uptime[0])) <> 0		; == Checks digit value of Uptime to see if it is 0 or not
						If Systemcheck($computer) = -1	
							
							If $Uptime[0] >= 7
								If RedirectOutput ("$RS_Logs\Systems_UpTime.txt") = 0 
									$Userloggedin = GetloginName($computer)	
									? $computer + "'s Uptime is: " + $Uptime[0] + " Days.  " + $Userloggedin ?
									$ = RedirectOutput("")
								EndIf 
							EndIf;
					
							Select
								Case $Uptime[0] >= 0 and $Uptime[0] < 7											
							
									If Exist ("$RS_Logs\$computer.SentEmail.txt")
										? "Email Tag File found Deleting .... "?
										del "$RS_Logs\$computer.SentEmail.txt"
									Endif
									?
								Case $Uptime[0] >= 7 and $UpTime[0] < 10
									
									? "System is being processed."
									$uptimex = $Uptime[0]								
									WriteEmail($computer,$uptimex)
									$Userloggedin = GetloginName($computer)					
									SendEmail($userloggedin,$computer,$uptimex)
									? "Writing Log File, and Sending Email"
									
								Case $Uptime[0] >= 10 										
									
									If Exist ("$RS_Logs\$computer.SentEmail.txt")
										? $computer + " is being rebooted.." + @CRLF
										;Shutdown ($computer, "Please Save Your Work,  This System Is Being Rebooted in 1 min.",60,1,1)
									Else
										? "Writing Log File, and Sending " + $userloggedin + " an Email to reboot their system."
										$uptimex = $Uptime[0]								
										WriteEmail($computer,$uptimex)						
										$Userloggedin = GetloginName($computer)				
										SendEmail($userloggedin,$computer,$uptimex)	
										? $computer + " Will not be Rebooted.." + @CRLF	
									Endif
							
							Endselect
						Else
							? "System is in Protected List.."+ @CRLF + @CRLF
						EndIf
					Else
					? "Uptime Check Failed!!!" + @CRLF
						If RedirectOutput ("$RS_Logs\System_UptimeChck_Failed.txt") = 0 
							?  "Uptime on: " + $computer + " Failed!!"
							$ = RedirectOutput("")
						EndIf
					EndIf
				Else
					? "$computer was skipped & Logged for review. WmiReturn Code: " + $WMICheck
					If RedirectOutput ("$RS_Logs\Errorlog.txt") = 0 
						? $computer + "'s Error Code is " + @error + " - " + @SERROR
						? "This system was skipped & Logged for review. WmiReturn Code: " + $WMICheck
						$ = RedirectOutput("")
					EndIf 
				Endif
		EndIf
	Else
		If RedirectOutput ("$RS_Logs\Systems_Offline.txt") = 0 
			$computer ?
			$ = RedirectOutput("")
		EndIf
	Endif
Next
; ----- System Reboot Email with attached System Uptimes Log -----
	? "Sendig admin email of systems with errors..."
	Shell 'bmail -s $EmailServer -t $IT_Email -f $IT_Email -a "Systems That need to be rebooted" -m $RS_Logs\Systems_uptime.txt'
	;del "$RS_logs\Errorlog.txt"
	
; ================== Functions Below This Point ====================

;----- This function just checks to make sure we don't reboot a pc that needs to stay up. --
Function Systemcheck($chkcomputer)		

	$result = 0
	$chkcomputer = TRIM(LCASE($chkcomputer))					
	$result = Ascan($DontReboot,$chkcomputer,0)				
	$systemcheck = $result										

EndFunction

; ---- Removes invalid email users ----
Function checkusers($users)		

	$result = 0
	$chkuser = TRIM(LCASE($users))					
	$result = Ascan($Userstoskip,$users,0)				
	$checkusers = $result										

EndFunction

;----- Pulls in the user that is logged into X machine  ----------------------------
Function GetloginName($chkcomputers)

	$usrloggedin = fnWMILoggedin (1,'$chkcomputers')			; == Current user logged in.
	$usrname = substr ($usrloggedin,6)							; == Removes "Domain\" Domain.
	$Getloginname = $usrname									; == Return Value.

EndFunction


;----- Sends an email to the user whos system has been up for more than 7 days, and sends email to administrator.
Function SendEmail($user,$system,$systemup)
If len(ltrim($user)) <> 0	; == This checks to make sure that a 0 digit value didn't show up for $User
	If checkusers($user) = -1
		Shell 'bmail -s $EmailServer -t $user@@$EmailSufix -f $IT_Email -a "(System Reboot Needed!) Uptime: $systemup Days." -m $RS_Logs\$system.SentEmail.txt'
	Else
		;Shell 'bmail -s $EmailServer -t $IT_Email -f $IT_Email -a "$system - $user Uptime: $systemup Days." -m $RS_Logs\$system.SentEmail.txt'
		;Shell '%compsec% net send \\$system "Alert Notice: This system has been turned on for $systemup days please reboot!, Thanks IT"'
	Endif
Else
	$Unli = "(User Not Logged In)"
	Shell 'bmail -s $EmailServer -t $IT_Email -f $IT_Email -a "$system - $Unli System Reboot Needed! It Has been Turned on for $systemup Days." -m $RS_Logs\$system.SentEmail.txt'
	;Shell '%compsec% net send \\$system "Alert Notice: This system has been turned on for $systemup days please reboot!, Thanks IT"'
Endif
EndFunction


;----- Writes the email file that is included in the body of the email sent. ------------
Function WriteEmail($cmpt,$sysup)

	If RedirectOutput ("$RS_Logs\$cmpt.SentEmail.txt",1) = 0  ; == Creates a Log File to indicate the sending of an email.
		? $cmpt + "'s Uptime is: " + $sysup + " Days."	
		?
		? "This is the Body of the Email that will be sent... Fill it in with whatever you want."
		
		$ = RedirectOutput("")
	EndIf 


LonkeroAdministrator
(KiX Master Guru)
2008-10-20 09:19 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

huge amount of reading.
thanks for sharing.
now, if glenn decides, it's not worth the vault, ppl can still learn by browsing your code here. \:\)


Indigo
(Fresh Scripter)
2008-10-20 09:21 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Yeah, its a nice script thought ppl might enjoy it.

If nothing else it could save someone some time if they wanted to do somthing similar \:\)

If anyone has any ideas on it plz let me know.. I would like to take this script to the next lvl ;\)

Indigo


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-21 12:47 AM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Well, the point of the Vault is so people can browse ready-made scripts, and not have to search through lots of other posts.

This is definitely useful (I'm sure the folks at helpdesks around the globe will enjoy this!), but can also use some polish. I'll pick every ripe nit I can find and report back - you and the rest of the incredible talent here on KORG can take it to the next level, and then we'll put the finished product in the Vault. Sound like a plan?

Glenn


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-21 12:53 AM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Indigo,

One more thing to consider - when you post larger projects like this, you might want to use PostPrep. The first post in the Advanced forum contains a download for both a GUI and Command Line version. Either version requires that you make a small adjustment to IE to permit scripted access to the clipboard. Once that's done, you can run postprep, copy the HTML to the clipboard, and paste it into a new post. It's important that you chose POST AS HTML for it to work properly. If you aren't familiar with simple HTML coding (paragraph and break, minimally) it's best to post the code in one message and your info/comments in another.

Another comment - most of us use 1-2 spaces for indents instead of tabs - makes the code easier to read here regardless of the posting method - less side-to-side scrolling. (PostPrep has an intelligent line-break algorithm that keeps lines short, too).

Glenn


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-21 01:39 AM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Postprepped, with some comments/changes


;=========================================================================================== 
; 
;	Title:   Windows XP Reboot of network clients 
;	Author:  Indigo 
;	Description:  Sends out emails at 7 Days, and Reboots at 10 
;	Version: .1 
; 
; =========================================================================================== 
 
BREAK on
 
 
; Need to declare variables! 
Dim $Var			; what it's used for 
 
 
 
; Need to set Kix Options (SetOption definitions) 
$ = SetOption('Explicit', 'On')
$ = SetOption('NoVarsInStrings', 'On')
$ = SetOption('NoMacrosInStrings', 'On')
$ = SetOption('WrapAtEOL', 'On')
 
 
 
; Define the Kix UDF library path once and reference it 
$KixLib = "\\server\share\path"
 
; include external UDFs from the standard kix lib path 
Call $KixLib + "\Comnetview.udf"
Call $KixLib + "\WmiUptime.udf"
Call $KixLib + "\Translatename.udf"
Call $KixLib + "\Ping.udf"
Call $KixLib + "\FnWMIloggedin.udf"
Call $KixLib + "\WMIConfirm.udf"
 
 
; Define settings - These might be best defined in an external INI file - use ReadProfileString to read them 
;$DontReboot  = Split(ReadProfileString('wsboot.ini', 'COMMON', 'NoReboot'), ',') 
;$Userstoskip = Split(ReadProfileString('wsboot.ini', 'COMMON', 'SkipUsers'), ',') 
;$EmailServer = ReadProfileString('wsboot.ini', 'COMMON', 'MailServer') 
;$EmailSufix  = ReadProfileString('wsboot.ini', 'COMMON', 'MailDomain') 
;RS_Logs      = ReadProfileString('wsboot.ini', 'COMMON', 'LogDrive') 
;IT_EMail     = ReadProfileString('wsboot.ini', 'COMMON', 'MailTo') 
 
$DontReboot = "Computer Name Here" , "Computer Name Here"
$Userstoskip = "User Name Here","User Name Here"
$EmailServer = "Email Server System Name" ; For email features to work you need Bmail and an open authentication turned on at your email server. 
$EmailSufix = "Company.com"
 
; == Intializing Log File Locations & IT - Email == 
$RS_Logs = "C:" 		    ; Don't use the \ because it won't work right. 
$IT_Email = "it@company.com"        ; Must have Double @@ for it to work right UNLESS YOU USE NOMACROSINSTRINGS option!. 
 
 
; == Clears Log Files If Script has been run before ==  
 
del "$RS_Logs\Systems_UpTime.txt"							
del "$RS_Logs\Systems_Offline.txt"		
 
$computers = COMNetView()			; == Locates computers on the network  
 
For Each $computer in $computers
 
  ;? "Pinging: " $computer 
  $online = Ping($computer,0,0,1)	; == Ping confirms computer online 
  If $online = "1"
    $winver = ReadValue("\\" + $computer + "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductName")
    ;? "Reading OS of " $computer " ( " $winver " )" 
    If $winver = "Microsoft Windows XP"
      $WMICheck = WMIConfirm('$computer')
        If $WMICheck <> 0
          $UpTime = WMIuptime($computer)
 
          ; == Displays Current System Information 
          "System: " + $computer +" (Online)" ?
          "OS: ( " $winver " )" ?
          "Uptime: " + $Uptime[0] + " Days" ?
          ; -------------------------------------- 
 
          If len(ltrim($uptime[0])) <> 0		; == Checks digit value of Uptime to see if it is 0 or not 
            If Systemcheck($computer) = -1
 
              If $Uptime[0] >= 7
                If RedirectOutput ("$RS_Logs\Systems_UpTime.txt") = 0
                  $Userloggedin = GetloginName($computer)
                  ? $computer + "'s Uptime is: " + $Uptime[0] + " Days.  " + $Userloggedin ?
                  $ = RedirectOutput("")
                EndIf
              EndIf
 
              Select
                Case $Uptime[0] >= 0 and $Uptime[0] < 7
 
                  If Exist ("$RS_Logs\$computer.SentEmail.txt")
                    ? "Email Tag File found Deleting .... "?
                    del "$RS_Logs\$computer.SentEmail.txt"
                  Endif
                  ?
                Case $Uptime[0] >= 7 and $UpTime[0] < 10
 
                  ? "System is being processed."
                  $uptimex = $Uptime[0]
                  WriteEmail($computer,$uptimex)
                  $Userloggedin = GetloginName($computer)
                  SendEmail($userloggedin,$computer,$uptimex)
                  ? "Writing Log File, and Sending Email"
 
                Case $Uptime[0] >= 10
 
                  If Exist ("$RS_Logs\$computer.SentEmail.txt")
                    ? $computer + " is being rebooted.." + @CRLF
                    ;Shutdown ($computer, "Please Save Your Work,  This System Is Being Rebooted in 1 min.",60,1,1) 
                  Else
                    ? "Writing Log File, and Sending " + $userloggedin + " an Email to reboot their system."
                    $uptimex = $Uptime[0]
                    WriteEmail($computer,$uptimex)
                    $Userloggedin = GetloginName($computer)
                    SendEmail($userloggedin,$computer,$uptimex)
                    ? $computer + " Will not be Rebooted.." + @CRLF
                  Endif
 
              Endselect
            Else
              ? "System is in Protected List.."+ @CRLF + @CRLF
            EndIf
          Else
          ? "Uptime Check Failed!!!" + @CRLF
            If RedirectOutput ("$RS_Logs\System_UptimeChck_Failed.txt") = 0
              ?  "Uptime on: " + $computer + " Failed!!"
              $ = RedirectOutput("")
            EndIf
          EndIf
        Else
          ? "$computer was skipped & Logged for review. WmiReturn Code: " + $WMICheck
          If RedirectOutput ("$RS_Logs\Errorlog.txt") = 0
            ? $computer + "'s Error Code is " + @error + " - " + @SERROR
            ? "This system was skipped & Logged for review. WmiReturn Code: " + $WMICheck
            $ = RedirectOutput("")
          EndIf
        Endif
    EndIf
  Else
    If RedirectOutput ("$RS_Logs\Systems_Offline.txt") = 0
      $computer ?
      $ = RedirectOutput("")
    EndIf
  Endif
Next
; ----- System Reboot Email with attached System Uptimes Log ----- 
  ? "Sendig admin email of systems with errors..."
  Shell 'bmail -s $EmailServer -t $IT_Email -f $IT_Email -a "Systems That need to be rebooted" -m $RS_Logs\Systems_uptime.txt'
  ;del "$RS_logs\Errorlog.txt" 
 
; ================== Functions Below This Point ==================== 
 
;----- This function just checks to make sure we don't reboot a pc that needs to stay up. -- 
Function Systemcheck($chkcomputer)
 
  $result = 0
  $chkcomputer = TRIM(LCASE($chkcomputer))
  $result = Ascan($DontReboot,$chkcomputer,0)
  $systemcheck = $result
 
EndFunction
 
; ---- Removes invalid email users ---- 
Function checkusers($users)
 
  $result = 0
  $chkuser = TRIM(LCASE($users))
  $result = Ascan($Userstoskip,$users,0)
  $checkusers = $result
 
EndFunction
 
;----- Pulls in the user that is logged into X machine  ---------------------------- 
Function GetloginName($chkcomputers)
 
  $usrloggedin = fnWMILoggedin (1,'$chkcomputers')			; == Current user logged in. 
  $usrname = substr ($usrloggedin,6)					; == Removes "Domain\" Domain. 
  $Getloginname = $usrname						; == Return Value. 
 
EndFunction
 
 
;----- Sends an email to the user whos system has been up for more than 7 days, and sends email to administrator. 
Function SendEmail($user,$system,$systemup)
If len(ltrim($user)) <> 0	; == This checks to make sure that a 0 digit value didn't show up for $User 
  If checkusers($user) = -1
    Shell 'bmail -s $EmailServer -t $user@@$EmailSufix -f $IT_Email -a "(System Reboot Needed!) Uptime: $systemup Days." -m $RS_Logs\$system.SentEmail.txt'
  Else
    ;Shell 'bmail -s $EmailServer -t $IT_Email -f $IT_Email -a "$system - $user Uptime: $systemup Days." -m $RS_Logs\$system.SentEmail.txt' 
    ;Shell '%compsec% net send \\$system "Alert Notice: This system has been turned on for $systemup days please reboot!, Thanks IT"' 
  Endif
Else
  $Unli = "(User Not Logged In)"
  Shell 'bmail -s $EmailServer -t $IT_Email -f $IT_Email -a "$system - $Unli System Reboot Needed! It Has been Turned on for $systemup Days." -m $RS_Logs\$system.SentEmail.txt'
  ;Shell '%compsec% net send \\$system "Alert Notice: This system has been turned on for $systemup days please reboot!, Thanks IT"' 
Endif
EndFunction
 
 
;----- Writes the email file that is included in the body of the email sent. ------------ 
Function WriteEmail($cmpt,$sysup)
 
  If RedirectOutput ("$RS_Logs\$cmpt.SentEmail.txt",1) = 0  ; == Creates a Log File to indicate the sending of an email. 
    ? $cmpt + "'s Uptime is: " + $sysup + " Days."
    ?
    ? "This is the Body of the Email that will be sent... Fill it in with whatever you want."
 
EndFunction
 


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-21 02:12 AM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

OK - now for the nits...

Use of "?" - this is a shorcut for @CRLF, or a NewLine, which should generally be placed at the END of the line of text. It is not (as in BASIC) a shortcut for a PRINT statement. Even more important is consistency - some messages have "?" in front while others have it at the end.

Variable Declarations - These are very important, and all vars should be declared, including those in functions. Some simple projects allow declaring all your vars on a single DIM line, separated by commas. As a project gets more advanced, you'd be much better served by declaring each var or var set on a single Dim line, with a comment that describes their use. When I refer to a "var set", it usually means similar vars, such as:
Dim $I, $J, $K ; index pointers
Dim $aComputers, $Computer ; Array of computers, loop enumerator

If you download my KGen tool, you'd see the result of a sanity check, which would issue dozens of warnings about variables.. It would also generate a report of which vars are declared/used where, which is useful in troubleshooting larger projects.

Use of double quotes - Since most DOS commands require double quotes, I perfer to use single quotes within Kix. This simplifies calling external apps. More than anything - be consistent!

Comments - a good start, but more is better, especially when you're sharing your code. YOU may know why you did something a certain way, but others won't. Further, will you remember why you did things that way 6 months from now? Maybe with heavy doses of Ginko-Biloba! ;\)

Debugging - Instead of commenting out critical but high-impact pieces of code, use a global $DEBUG variable. Then, you can do something like:
$Cmd = 'bmail -s ' + $EmailServer + ' -t ' $IT_Email
If $DEBUG
'DEBUG: -identifier-: Shell' $Cmd
Else
Shell $Cmd
; do error check!!!
EndIf

Command strings - should be built using a $Cmd var, which lets you easily display or run a command, as shown by the debug process above. The process in your script has variables in the string, which is a bad idea. Here's an example of how command vars are built
$Cmd = '%COMSPEC% /c ' ; define the command shell
$Cmd = $Cmd + 'bmail.exe ' ; command to run
$Cmd = $Cmd + '-s ' + $EmailSever + ' ' ; add the mailserver arg
and so on... This is much easier to check for missing quotes, too.

Ramifications of Explicit option are that variables that default to GLOBAL will need to either be declared as global (messy) or passed to functions (need careful review) to work properly. $UsersToSkip and the CheckUsers function are one example of this, although several functions seem to rely on global vars.

Eliminate repetetive definitions - Instead of defining the complete path in the Include statements (which can't process vars), define the path once and use the Call statement instead. Call runs after the script initializes and can take advantage of variable references. If you use KGen, it will resolve the dependencies automatically and include those functions in the final script, eliminating the need to make the library available on the network and making the finished script more portable.

Use of customized data - While keeping all user/site specific data in one place in vars is good, the next step would be to place it outside of the script entirely using a config file. Kix has powerful INI read/write capabilities that you could leverage. You could even write it in such a way that if the config file was empty or not found, you could prompt the user to update it on the spot. Might even ask if a predefined config was available on the network? Several ways this could go, really.

Well, I suppose that's enough for now. If this were presented in my class, you'd score high for concept and thought. The points I've outlined will make the tool more portable, reliable, and supportable - better suited for an enterprise helpdesk environment.

I'll look forward to seeing progress on this!

Glenn


NTDOCAdministrator
(KiX Master)
2008-10-21 02:38 AM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

I agree with all that Glenn has said. He is very good at commenting and polishing up scripts and explaining them.

One point I don't like (and I fear that I'm alone with this one but I'll complain again anyways)

Not that it is wrong or that it doesn't do as it's supposed to but I don't like the use of a single $ for use as a variable.

$ = SetOption('Explicit', 'On')
$ = SetOption('NoVarsInStrings', 'On')
$ = SetOption('NoMacrosInStrings', 'On')
$ = SetOption('WrapAtEOL', 'On')


I find it very difficult to track down and modify single entries in a large script because often a coder will use that single $ either in script or UDF and that makes it difficult to do an automated Search & Replace and I have to confirm all changes.

In my opinion you shouldn't use a single $ and you shouldn't reuse the same var name over again if possible. Often the single $ is simply used for preventing screen output or holding a var that will be of no further use later on in the script and could easily be used again.

Most people don't do this type of change I suppose or they work differently than I do so it's not an issue for them.

Just my own personal preference I suppose.


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-21 04:12 AM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Yeah, well, OK - I can see the "$" issue. $Rv or $Rc (ReturnValue or ReturnCode) are better.

I do try to limit my use of the $, and also follow a set of "rules" for my coding projects:
  • Global vars are $ALLCAPS
  • Local vars are $MixedCase
  • Macros are treated as globals, since they are the same regardless of being in a function or the main code, and are @ALLCAPS
  • Commands & Functions are MixedCase, and all operators, commands, functions, arguments/parameters, variables and values are separated by a space. This helps in formatting with PostPrep when long-line wrapping is enabled.
  • Any local var defined in a function is prefaced with a "_", as in $_VarName. This avoids conflicts in naming with other UDFs when explicit is not enabled, and especially conflicts with global vars.
  • Variable re-use is limited to those capturing return values, and those used to index/increment a pointer.
  • While I don't use strict Hungarian notation, I do preface most arrays with "a" - as in $aComputers for an array of computer names. Since Kix uses variants (variables that can hold anything) the notation loses some value. I often, however, reference variables that must hold a specific type of data that's been cast, like $dCTime for a double-precision CTime representation of the current date/time. This is one rule that - for me - can be bent and twisted to suit my needs and my mood. I have too much code and too many UDFs where this isn't followed to get strict about it now.
The real point is to find a style that works for you and presents well to others. Develop that style and stick with it. It may change and evolve over time, but it shouldn't waver constantly.

Glenn


Indigo
(Fresh Scripter)
2008-10-21 03:55 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

I apprecate you guys taking the time to look over the code. I am going to see what i can do about cleaning up the code, and such.

I like the idea of reading the ini file and reading the values that way. i also like the idea of prompting for them.

Interface changes are something i need to learn about. Would it be better to use kixforms? or just a standard imput.


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-21 04:02 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

For this, just CLS and prompt for input - I would not get fancy at this point, as there are only 5 parameters.

Glenn


Indigo
(Fresh Scripter)
2008-10-21 04:46 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Yeah,

I ran your Kgen script, and it generated all kinds of data to sift though.

I will be digging through it today.

Once i have a working updated copy of the script i will post it again.


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-21 05:11 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Yeah, it will do that. ;\)

Realize that they are warnings, not errors - it's up to you to determine what to fix or not. The most common thing to ignore is a mismatched quote or Paren on lines X and Y - it sees it as a mismatched set, and not a single string broken across multiple lines. Still, better to have been warned...

Glenn


Indigo
(Fresh Scripter)
2008-10-21 08:09 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Oddly enough i was trying to make some of the changes you mentioned, and i Came across somthing..

I tried making this Change:
 Code:
Include $KixLib + "\Comnetview.udf"
Include $KixLib + "\WmiUptime.udf"
Include $KixLib + "\Translatename.udf"
Include $KixLib + "\Ping.udf"
Include $KixLib + "\FnWMIloggedin.udf"
Include $KixLib + "\WMIConfirm.udf"


I was told that Include can't have variables in it.

Also I noticed that When i have
 Code:
$Rc = SetOption('Explicit', 'On')


I have to debug all the UDF Code.. Is there a way to tell it to exclude UDFs from being processed that way?


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-21 09:03 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Oops! I know I changed that, but I must not have saved it before running PostPrep. I changed all of the Include statements to Call statements, which allow vars. (just shows that I'm not nearly perfect ) It's fixed now.

There's no direct way to tell KGen not to process UDFs. Since it relies on locating UDFs based on %KixLibPath%, set that to a null value. Make sure there are no .UDF or .KXF files in the project folder.

Glenn


Indigo
(Fresh Scripter)
2008-10-21 10:31 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

In the example below when I am setting up the variables to be passed do I have to demention the variables again if the Var names are the same as previously Dim'ed Variables.

For Example $EmailServer, or $IT_Email

 Code:
Function SendEmail($User,$system,$systemup,$EmailServer,$IT_Email,$EmailSufix,$RS_Logs,$Userstoskip)
; == Declaring Variables
Dim $User			; User to be emailed
Dim $System			; Hostname of current system
Dim $Systemup		; Uptime of Current system
Dim $Unli			; Defined as (User Not Logged In) - Incase user isn't logged in

;Dim $EmailSufix 	; Global and needs to be passed.
;Dim $IT_Email 		; is Global and needs to be passed.
;Dim $RS_log		; is Global and needs to be passed.


If len(ltrim($User)) <> 0	; == This checks to make sure that a 0 digit value didn't show up for $User
	If checkusers($User,$Userstoskip) = -1
		;Shell 'bmail -s $EmailServer -t $User@@$EmailSufix -f $IT_Email -a "(System Reboot Needed!) Uptime: $systemup Days." -m $RS_Logs\$system.SentEmail.txt'
	Else
		;Shell 'bmail -s $EmailServer -t $IT_Email -f $IT_Email -a "$system - $user Uptime: $systemup Days." -m $RS_Logs\$system.SentEmail.txt'
		;Shell '%compsec% net send \\$system "Alert Notice: This system has been turned on for $systemup days please reboot!, Thanks IT"'
	Endif
Else
	$Unli = "(User Not Logged In)"
	Shell 'bmail -s $EmailServer -t $IT_Email -f $IT_Email -a "$system - $Unli System Reboot Needed! It Has been Turned on for $systemup Days." -m $RS_Logs\$system.SentEmail.txt'
	;Shell '%compsec% net send \\$system "Alert Notice: This system has been turned on for $systemup days please reboot!, Thanks IT"'
Endif
EndFunction



Also When I call a second Function inside of the first one like below for Checkusers do I have to pass the $Userstoskip Variable to the Function SendEmail First and then to the Function checkusers for it to pass the information along or can I just call checkusers with he added $Userstoskip variable and it will work fine.


 Code:
If checkusers($User,$Userstoskip) = -1
		;Shell 'bmail -s $EmailServer -t $User@@$EmailSufix -f $IT_Email -a "(System Reboot Needed!) Uptime: $systemup Days." -m $RS_Logs\$system.SentEmail.txt'
	Else
		;Shell 'bmail -s $EmailServer -t $IT_Email -f $IT_Email -a "$system - $user Uptime: $systemup Days." -m $RS_Logs\$system.SentEmail.txt'
		;Shell '%compsec% net send \\$system "Alert Notice: This system has been turned on for $systemup days please reboot!, Thanks IT"'
	Endif
Else
	$Unli = "(User Not Logged In)"
	Shell 'bmail -s $EmailServer -t $IT_Email -f $IT_Email -a "$system - $Unli System Reboot Needed! It Has been Turned on for $systemup Days." -m $RS_Logs\$system.SentEmail.txt'
	;Shell '%compsec% net send \\$system "Alert Notice: This system has been turned on for $systemup days please reboot!, Thanks IT"'
Endif


Thanks!

Indigo


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-21 10:52 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

The environment of a function is unique - the variable $User defined in the main program as a local will not be visible in the function. Thus, if you don't define it in the function, you'll get an undeclared var error when Explicit is enabled. You need to define the vars in the functions, too.

That's why I add the "_" to my function var names - just to reinforce that they are unique to the function. It also protects against corruption due to variable reuse if Explicit is off.

As far as passing vars to a function, you need to pass everything that the function will need. Remember that the function gets a copy of the data, not the actual data, so you can't just modify the data in a function the way you can in a subroutine. (Subroutines are in the same memory context as the main program.) So, in your example, you'd need to pass EMailServer, IT_Email, System, etc..

Glenn


Indigo
(Fresh Scripter)
2008-10-22 05:57 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

I am cose to having Version .2 done. I have made most your suggested changes.

I however, can't run explisit on because I would have to debug every line of code that is brought into my script for accuracy.

I have cleaned up the display output, functions, and removed duplicate code.

the last thing I am tiding up is he email funcion. I will more than likely be adding your suggestion to the $CMD variable to create the emailing funciton.

Thanks for all the help!


Indigo
(Fresh Scripter)
2008-10-22 08:06 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

YAY!!! V.2 is finished! haha \:\) I am a Tad Pumped about it. Looks cleaner, and Seemingly runs smoother.

I only 2 options disabled at the moment.
Auto Rebooting:
 Code:
If Exist ($RS_Logs + "\" + $Computer + ".SentEmail.txt")
    @CRLF + $Computer + " Is being rebooted.." + @CRLF
    ;Shutdown ($computer, "Please Save Your Work,  This System Is Being Rebooted in 1 min.",60,1,1)
Else


This Section Below Sends a Net Send Message to the Machine when a users isn't logged in, so the next time they log in they will get a Net Send message telling them to reboot.

 Code:
If checkusers($_User,$_Userstoskip) = -1		; Makes sure certian users don't get emails.
	Shell $_Email
Else
	; ***** Shell '%compsec% net send \\$_System "Alert Notice: This system has been turned on for $systemup days please reboot!, Thanks IT"'
Endif


To Get both of these options working you need to UnComment them.

Well with no Further Adue Here is V.2 \:\)

 Code:
; ===========================================================================================
;
;	Title:   Windows XP Reboot of network clients
;	Author:  Indigo			
;	Description:  Sends out emails at 7 Days, and Reboots at 10	
;	Version: .2
;
; ===========================================================================================

; == Seting Kixtart Options == 

$Rc = SetOption('Explicit', 'Off')
$Rc = SetOption('NoVarsInStrings', 'On')
$Rc = SetOption('NoMacrosInStrings', 'On')
$Rc = SetOption('WrapAtEOL', 'On')

Break on

; == Declaring Variables. == 

Dim $DontReboot		; == Systems that won't be rebooted
Dim $UserstoSkip	; == Users that will be skipped
Dim $EmailServer	; == The Hostname of the Email Server
Dim $EmailSufix		; == The "company.com" in the Email addresses
Dim $RS_Logs		; == The Log Location \\server\share\path\
Dim $IT_Email		; == The Administrator Email
Dim $Rc			; == Return Code for Kixtart Options
Dim $Computers		; == An Array that holds all the Computers Comnetview gathers
Dim $Computer		; == Each Compuer in Computers
Dim $Online		; == Systems Online / Not Online
Dim $Winver		; == Windows Version
Dim $WMICheck		; == WmiCheck pass/fail
Dim $Uptime		; == Uptime in Days IE. 10
Dim $Kixlib		; == Kix Library location

; == Kixlib Defined ==
$Kixlib = "\\Server\Share\Path"						; Define Where your Kixtart Lib is here Do not place a trailing \
; === Includes all Udfs needed for this script ===

 Call $Kixlib + "\Comnetview.udf"
 Call $Kixlib + "\WmiUptime.udf"
 Call $Kixlib + "\Translatename.udf"
 Call $Kixlib + "\Ping.udf"
 Call $Kixlib + "\FnWMIloggedin.udf"
 Call $Kixlib + "\WMIConfirm.udf"

; == Intializing  Computer & User Special Consideration Veriables ==  ***** Variables below must be changed to needed Values ******

$DontReboot  = "Computer Name Here" , "Computer Name Here"		; Computers to Be Skipped
$Userstoskip = "User Name Here","User Name Here"			; Users to be Skipped
$EmailServer = "Email Server Host Name" 				; HostName of Email Server
$EmailSufix  = "Email Suffix"						; Sufix of Email Address Company.com

$RS_Logs = "\\server\share\path" 					; Don't use the trailing \ because it won't work right
$IT_Email = "Admin@company.com"       					; Email Address of System Admin or Group

; == Clears Log Files If Script has been run before == 		       **********************************************************

del $RS_Logs + "\Systems_UpTime.txt"							
del $RS_Logs + "\Systems_Offline.txt"		

$computers = COMNetView()						; == Locates computers on the network 
CLS
For Each $computer in $computers											
	
	$online = Ping($computer,0,0,1)	; == Ping confirms computer online
	If $online = "1"														
		$winver = ReadValue("\\" + $computer + "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductName")
		If $winver = "Microsoft Windows XP" 								
			$WMICheck = WMIConfirm($computer)
				If $WMICheck <> 0										
					$UpTime = WMIuptime($computer)
					$Userloggedin = GetloginName($Computer)	
					
					; == Displays Current System Information
					CLS
					"System: " + $Computer +" (Online)" + @CRLF
					"OS: (" $Winver ")" + @CRLF
					"User: " + $Userloggedin + @CRLF
					"Uptime: " + $Uptime[0] + " Days" + @CRLF
					; --------------------------------------					
					
					If len(ltrim($Uptime[0])) <> 0					; == Checks digit value of Uptime to see if it is 0 

or not
						If Systemcheck($Computer,$DontReboot) = -1		; == Checks to make sure system isn't in the 

Protected list
							
							If $Uptime[0] >= 7
								If RedirectOutput ($RS_Logs + "\Systems_UpTime.txt") = 0 
									$Userloggedin = GetloginName($computer)	
									? $computer + "'s Uptime is: " + $Uptime[0] + " Days.  " + $Userloggedin ?
									$ = RedirectOutput("")
								EndIf 
							EndIf;
					
							Select
								Case $Uptime[0] >= 0 and $Uptime[0] < 7								

			
							
									If Exist ($RS_Logs + "\" + $computer + ".SentEmail.txt")
										"Email Tag File found Deleting .... < 7 " + @CRLF
										del $RS_Logs + "\"+ $computer + ".SentEmail.txt"
									Endif
									@CRLF
									
								Case $Uptime[0] >= 7 and $UpTime[0] < 10
									
									"System is being processed." + @CRLF
									WriteEmail($computer,$Uptime[0],$RS_Logs)
									

SendEmail($Userloggedin,$Computer,$Uptime[0],$EmailServer,$IT_Email,$EmailSufix,$RS_Logs,$Userstoskip,0)
									"Writing Log File, and Sending Email >= 7 And < 10 " + @CRLF
									
								Case $Uptime[0] >= 10 										
									
									If Exist ($RS_Logs + "\" + $Computer + ".SentEmail.txt")
										@CRLF + $Computer + " Is being rebooted.." + @CRLF
										;Shutdown ($computer, "Please Save Your Work,  This System Is Being Rebooted 

in 1 min.",60,1,1)
									Else
										"Writing Log File, and Sending Email >= 10 " + @CRLF
										WriteEmail($computer,$Uptime[0],$RS_Logs)
										

SendEmail($Userloggedin,$Computer,$Uptime[0],$EmailServer,$IT_Email,$EmailSufix,$RS_Logs,$Userstoskip,0)
									Endif
							
							Endselect
						Else
							@CRLF + "System Is In The Protected List..(Skipping)" + @CRLF
						EndIf
					Else
					@CRLF +  "Uptime Check Failed!!! (Skipping & Logging)" + @CRLF + "Logfile: " + $RS_Logs + 

"\System_UptimeChck_Failed.txt" + @CRLF
						If RedirectOutput ($RS_Logs + "\System_UptimeChck_Failed.txt") = 0 
							"Uptime on: " + $computer + " Failed!!" + @CRLF
							$ = RedirectOutput("")
						EndIf
					EndIf
				Else
					$computer + " was skipped & Logged for review. WmiReturn Code: " + $WMICheck + @CRLF
					If RedirectOutput ($RS_Logs + "\Errorlog.txt") = 0 
						$computer + "'s Error Code is " + @error + " - " + @SERROR + @CRLF
						"This system was skipped & Logged for review. WmiReturn Code: " + $WMICheck + @CRLF
						$ = RedirectOutput("")
					EndIf 
				Endif
		EndIf
	Else
		If RedirectOutput ($RS_Logs + "\Systems_Offline.txt") = 0 
			$computer ?
			$ = RedirectOutput("")
		EndIf
	Endif
Next
; ----- System Reboot Email with attached System Uptimes Log -----
	
	SendEmail($Userloggedin,$Computer,$Uptime[0],$EmailServer,$IT_Email,$EmailSufix,$RS_Logs,$Userstoskip,1)

; ================== Functions Below This Point ====================

;----- This function just checks to make sure we don't reboot a pc that needs to stay up. --
Function Systemcheck($_Chkcomputer,$_DontReboot)		

; == Declaring Variables
Dim $_Result		; Holds the Result of the calculation
Dim $_Chkcomputer	; Computer to be checked
Dim $_DontReboot 	; Global Variable Transfered to Function.

	$_Result = 0
	$_Chkcomputer = TRIM(LCASE($_Chkcomputer))					
	$_Result = Ascan($_DontReboot,$_Chkcomputer,0)				
	$Systemcheck = $_Result										

EndFunction

; ---- Removes invalid email users ----
Function checkusers($_Users,$_Userstoskip)		

; == Declaring Variables
Dim $_Result		; Holds the Result of the calculation
Dim $_Chkuser		; User to be checked
Dim $_Users		; User passed to function (raw)
Dim $_Userstoskip 	; Global Variable Transfered to Function.

	$_Result = 0
	$_Chkuser = TRIM(LCASE($_Users))					
	$_Result = Ascan($_Userstoskip,$_Users,0)				
	$Checkusers = $_Result										

EndFunction

;----- Pulls in the user that is logged into X machine  ----------------------------
Function GetloginName($_Chkcomputers)

; == Declaring Variables
Dim $_Usrloggedin	; User Logged into current system in current format Domain\Username
Dim $_Username		; Just username by itself

	$_Usrloggedin = fnWMILoggedin (1,$_Chkcomputers)			; == Current user logged in. Remove ' ' around $_Chkcomputers may be needed
	$_Usrname = substr ($_Usrloggedin,6)					; == Removes "Domain\" Domain.  May need to look into a different way to 

shorten

If len(ltrim($_Usrloggedin)) = 0	; == Checks for a 0 digit value assigned to user, if it did (User not logged) in is Returned.
	$_Unli = "(User Not Logged In)"
	$Getloginname = $_Unli
	Return
Endif

$Getloginname = $_Usrname

EndFunction


;----- Sends an email to the user whos system has been up for more than 7 days, and sends email to administrator.
Function SendEmail($_User,$_System,$_Systemup,$_EmailServer,$_IT_Email,$_EmailSufix,$_RS_Logs,$_Userstoskip,$_AdminEmail)
; == Declaring Variables
Dim $_User		; User to be emailed
Dim $_System		; Hostname of current system
Dim $_Systemup		; Uptime of Current system
Dim $_Unli		; Defined as (User Not Logged In) - Incase user isn't logged in
Dim $_EmailSufix 	; Global Variable Transfered to Function.
Dim $_IT_Email 		; Global Variable Transfered to Function.
Dim $_RS_log		; Global Variable Transfered to Function.
Dim $_Email		; Building Block Variable for Sending Emails.

			; Through a Variable for On/Off maybe setup a Debug Admin Feature, so only admin is emailed

$_Email = 'bmail'
$_Email = $_Email + ' -s '
$_Email = $_Email + $_EmailServer
$_Email = $_Email + ' -f ' + $_IT_Email	
	
	If $_AdminEmail = 1
		$_Email = $_Email + ' -t ' + $_IT_Email
		$_Email = $_Email + ' -a ' + '"Systems That need to be rebooted"'
		$_Email = $_Email + ' -m ' + $_RS_Logs + '\Systems_uptime.txt'
	Else
		$_Email = $_Email + ' -t ' + $_IT_Email		; Change this back t $_User so it sends the email to the user.
		$_Email = $_Email + ' -a ' + '"(System Reboot Needed!) Uptime: ' + $_Systemup + ' Days."'
		$_Email = $_Email + ' -m ' + $_RS_Logs + '\' + $_System + '.SentEmail.txt'
	EndIf

If checkusers($_User,$_Userstoskip) = -1		; Makes sure certian users don't get emails.
	Shell $_Email
Else
	;Shell '%compsec% net send \\$_System "Alert Notice: This system has been turned on for $systemup days please reboot!, Thanks IT"'
Endif

EndFunction


;----- Writes the email file that is included in the body of the email sent. ------------
Function WriteEmail($_Computer,$_Uptime,$_RS_Logs)

; == Declaring Variables
Dim $_Computer 		; Hostname of Current System
Dim $_Uptime		; Uptime of Current System
Dim $_RS_Logs		; Handles Log locations

	If RedirectOutput ($_RS_Logs + "\"+ $_Computer + ".SentEmail.txt",1) = 0  ; == Creates a Log File to indicate the sending of an email.
		@CRLF $_Computer + "'s Uptime is: " + $_Uptime + " Days."	
		@CRLF
		@CRLF "This is the Body of the Email that will be sent... Fill it in with whatever you want."
		@CRLF
		$ = RedirectOutput("")
	EndIf 

EndFunction


LonkeroAdministrator
(KiX Master Guru)
2008-10-22 09:12 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

LOL.
I rock. (long line police mantra)


Indigo
(Fresh Scripter)
2008-10-22 09:16 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

hehe yeah,

Some of those Functions i call have a crap load of variables being passed.


LonkeroAdministrator
(KiX Master Guru)
2008-10-22 09:20 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

that wouldn't be a problem if you lonkenized your code. :p

for the newbies, who don't know what that means, kixtart dictionary reference is required.
 Quote:

lon·ke·nize
–verb (used with object)
1. to compress and to cryptify source code in such a manner by a person, that it's hard for another person to read or comprehende and at the same time minimize the amount of strokes required for the fully functional code.

see also: KiXgolf


Indigo
(Fresh Scripter)
2008-10-22 09:34 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

ahha nice!

I will work on it ;\)


Mart
(KiX Supporter)
2008-10-23 09:16 AM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

 Originally Posted By: Indigo
ahha nice!

I will work on it ;\)


Nooooooooo! \:o
Please do not Lokenize the code. You're messing with everybody’s mind if you do that.


Indigo
(Fresh Scripter)
2008-10-23 03:10 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

:).. I am just kidding as well

I did notice that there is a bug in my script. When it edits the user logged in from its raw data.. its a solid calcuation of stip off the prefix info. For example Domain\username. It is set to strip of the exact numbers of my domain name. I don't think everyone has the same numberes, so i wanted to mention that the username won't come back correctly if it isn't properly substringed.

here is the peice of code that will change this.

 Code:
Function GetloginName($_Chkcomputers)

; == Declaring Variables
Dim $_Usrloggedin	; User Logged into current system in current format Domain\Username
Dim $_Username		; Just username by itself

	$_Usrloggedin = fnWMILoggedin (1,$_Chkcomputers)			; == Current user logged in. Remove ' ' around $_Chkcomputers may be needed
	$_Usrname = substr ($_Usrloggedin,6)	   ; ************ Edit the 6 To whater your Domain\ is.	 

shorten

If len(ltrim($_Usrloggedin)) = 0	; == Checks for a 0 digit value assigned to user, if it did (User not logged) in is Returned.
	$_Unli = "(User Not Logged In)"
	$Getloginname = $_Unli
	Return
Endif

$Getloginname = $_Usrname

EndFunction



Glenn BarnasAdministrator
(KiX Supporter)
2008-10-23 03:27 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Good, 'cause I'd have to track you down and beat you into submission with wet noodles if you weren't.

As for your issue above, the output format is DOMAIN\userid, so
$_UserName = Split(fnWMILoggedIn(), '\')[1]

This splits the output of the function into a 2 element array on the "\" char, and stores only the second element into the $_UserName var - no need to know the length of the domain name that way.

Glenn


Indigo
(Fresh Scripter)
2008-10-23 04:47 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Wicked Sweet.

I will adjust the code to accomidate for that.

Hey while i am here, i have noticed that i have a limitation to my code.

My email feature only knows who to email when they are logged into the system the script is quering. However, if they are logged out no username is generated and i am unable to email the user of that system. Can you think of an easy way to pull usernames for the email portion?

And i guess that brings up another goood point... if someone is using this script and the logon names don't match their email address names.. the emailing function won't work at all..

Indigo


Gargoyle
(MM club member)
2008-10-23 04:54 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

YOu can do an AD lookup to retrieve an Email address. Look at the UDF QUERYLDAP().

Indigo
(Fresh Scripter)
2008-10-23 04:59 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Well,

Glenn that Change you suggested worked Like a Charm!! No need to worry about the length of the user name.

Hey, just as a side note... How does split know to return only the second half of the split string.

I was looking at it.. and it didn't jump out at me?


Mart
(KiX Supporter)
2008-10-23 05:01 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

 Originally Posted By: Indigo

....
Hey, just as a side note... How does split know to return only the second half of the split string.

I was looking at it.. and it didn't jump out at me?


That is the [1] part. An array starts at [0] if there is some data in it so [1] is the second element.


Indigo
(Fresh Scripter)
2008-10-23 05:02 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

haha Nice!

Go figure \:\)

Thanks Mort


Indigo
(Fresh Scripter)
2008-10-23 05:07 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

I was looking at fnLdapquery, and its a tad confusing.

Lets say a manage to get the email out of AD, i am unclear how i would link this to the machine that the user was logged in at.


OO oOO i think i got it.

I could do a queary to see who the last person was logged into the system. then i could compare it with the current user.. if they matched use that username.

if they didn't use the one the current user logged in.

if no one is logged in I could then use the last user logged into that pc.

\:\)

that sounds like a good plan.


AllenAdministrator
(KiX Supporter)
2008-10-23 05:20 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

See if this could help with the email addresses
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Main=25474&Number=188570#Post188570


Indigo
(Fresh Scripter)
2008-10-23 05:41 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

I like this idea, it would work great for the users that stayed logged into the system and i was able to pull their user name, but on the flip side i need to figure out how to tie a machine to a user, so when i don't have a user logged into the machine i can still send an email to that user to reboot their system.

I was orginally thinking i could do that by checking who the last person that logged into the system, but i have been digging around, and i don't see any udfs that grab the last user logged in, and are designed to work remotely \:\(


Kdyer
(KiX Supporter)
2008-10-23 05:45 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

 Originally Posted By: Indigo

I was orginally thinking i could do that by checking who the last person that logged into the system, but i have been digging around, and i don't see any udfs that grab the last user logged in, and are designed to work remotely \:\(


If memory serves, you can grab the last logged in person from WMI..

Kent


Indigo
(Fresh Scripter)
2008-10-23 06:16 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

I am unfamilar with WMI ... is there any good docs on how to use it?

Indigo


Kdyer
(KiX Supporter)
2008-10-23 06:53 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

The UDF WMIQuery() in the UDF section covers it pretty well. If memory serves, there is a link to MSDN in the header of it to what you can query on.

Kent


Indigo
(Fresh Scripter)
2008-10-23 08:00 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Cool,

I will look at that today,

Hey !! just wanted to let everyone know that V.3 is out, and I have corrected Post One to reflect the changes made, and future changes.. I am still looking for a better way to pull emails for XXX machine, so the user on the system will be notified..

I will be digging into the Wmi idea of the last user logged on I think this has some potential..

Thats it for now,

BBL Guys


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-23 09:39 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Consider this:

You are trying to id a user on a computer, and you reboot the computer. You need to tell somebody the computer was restarted.

Instead of getting complicated with email, user lookups, etc, you can create a scheduled task that runs a very simple kix script. That script has only a MessageBox() function that will pop up and tell whoever logs on that the system had been rebooted by your script. The tcLib can create an At Logon task on the target computer, and can even specify a script on a central share. Cuts down on emails, too.

BTW - if you run AutoUpdates, that's what MS does after an unattended restart.

Glenn


Indigo
(Fresh Scripter)
2008-10-27 04:13 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Well Guys and Gals,

I have been thinking...

I will probably make one more change.. Creating the Config file. Once that section is complete I will Let V.4 Sail.

After that I don't think their would be any big reason to keep working on this with updates unless someone wanted to see something spacific in it.

thanks Again for all your help!!!


Indigo
(Fresh Scripter)
2008-10-27 04:21 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

While i am here,

Would someone point me in the right direction on how to write a config file?

Indigo


Mart
(KiX Supporter)
2008-10-27 04:25 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

You could use an ini file.
Writing and reading to and from an ini file can be done with the WriteprofileString() and ReadProfileString() functions.

[sectionname]
ValueA=xx
ValueB=yy


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-27 04:32 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Here's the general idea:

To start, create a file using notepad. Give it a reasonable name, with a .INI extension. It should look something like this:
[CONFIG]
ValueName1=data
ValueName2=data

Each "ValueName" represents one of the config parameters from your script, and the "data" is the initial definition. The CONFIG section contains all of the script-common data values, like MailServer, MailUser, MailSendTo, and so on.. You could create workstation-specific sections:
[PCNAME]
Skip=1
for workstation values - in that example, if you read the Skip value from the @WKSTA section and determined that the value was "true" (see my Bool() UDF), you could skip that PC. Would also make other customizations possible, like WeekendOnly or MaxDays.

Replace your $VarName=Value declarations in the script with
$VarName = ReadProfileString($ConfigFile, 'CONFIG', 'ValueName')
commands. - then test. Change some of the INI settings and verify that the changes are accepted.

Then, you can add some code that determines if the config file is present. If it isn't, it can prompt for the required data and create the config file with WriteProfileString commands.

I find that creating config files is often an evolutionary process, so I don't create tools to create/manage them until i feel they are complete.

Glenn


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-27 04:34 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

BTW - the "CONFIG" section name is literally called "CONFIG", while the "PCNAME" section is actually the name of a specific PC that requires special treatment. I'd only add PC-specific sections if you have more than one PC-specific configuration parameter.

Glenn


Indigo
(Fresh Scripter)
2008-10-27 04:41 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Thanks! Glenn

I will see what I can come up with.


Indigo
(Fresh Scripter)
2008-10-28 08:06 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

I am noticing i am getting some odd results from the ReadProfileString.

I setup ini file like so..

[Section]
value1=data
value2=data

result:

value1
value2

no data..

Now if i use a incramentor like

ReadprofileString("ini file","Section",value + $Index)

i get he correct results but i also get a trailing LineFeed.

 Code:
Function ReadConfig($Section)
$Value = ""
$Config = ""
$aConfig = ""
	$Index = 1
	$Value = ReadProfileString(".\RS_Config.ini", $Section, "Value" + $Index)

		While len(ltrim($Value)) <> 0	
	
			$Config = $Config + $Value + ","
			$Index = $Index + 1
			$Value = ReadProfileString(".\RS_Config.ini", $Section, "Value" + $Index)
		
		LOOP 
	$aConfig = Split($Config,",")
	$ReadConfig = $aConfig		
		
EndFunction



Glenn BarnasAdministrator
(KiX Supporter)
2008-10-28 08:14 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Seems way too complicated...

In the beginning of your script, just add
$CfgFile = @SCRIPTDIR + 'RS_Config.ini'
and replace each
$SomeVar = 'xxx'
with
$SomeVar = ReadProfileString($CfgFile, 'CONFIG', 'SomeVar')

Sorry if that wasn't clear yesterday - the varnames in the INI file can be descriptive, or even match the varnames in the script to keep things very simple, just without the "$".

Glenn


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-28 08:24 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

OK - went back to your code to pull a direct example:
 Code:
$DontReboot  = Split(ReadProfileString($CfgFile, 'CONFIG', 'NoReboot'), ',')	; Computers to Be Skipped
$Userstoskip = Split(ReadProfileString($CfgFile, 'CONFIG', 'SkipUsers'), ',')	; Users to be Skipped - (user not logged in) Must remain in list!!!
$EmailServer = ReadProfileString($CfgFile, 'CONFIG', 'MailServer') 		; HostName of Email Server
$EmailSufix  = ReadProfileString($CfgFile, 'CONFIG', 'MailDomain')		; Sufix of Email Address Company.com

$RS_Logs = ReadProfileString($CfgFile, 'CONFIG', 'LogPath')			; Don't use the trailing \ because it won't work right
$IT_Email = ReadProfileString($CfgFile, 'CONFIG', 'MailTo')			; Email Address of System Admin or Group

The config file should look like this:
 Code:
[CONFIG]
NoReboot=host1,host2,host3
SkipUsers=Fred,Wilma,Betty,Barney
MailServer=mailhost.mydomain.com
MailDomain=mydomain.com
LogPath=C:\Logs\rsinfo.log
MailTo:MrSlate

Glenn


LonkeroAdministrator
(KiX Master Guru)
2008-10-28 10:03 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

ok, just maybe I'm stupid, but...

why would you need separate maiDomain-property in the ini-file?


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-28 10:10 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Maybe you're not stupid - maybe you just didn't review the code ;\)

There's an array of userIDs, knowing the mail domain might let you send mail to those users by combining the two? Maybe further review and potential suggestions are needed?

I just grabbed the variable assignments from the top of the code and changed then to ReadProfileString calls as an example, since I thought the original method to read the INI file was too complicated. One step at a time - this is turning into a great "how to create, tweak, and polish a script" process.

Glenn


Indigo
(Fresh Scripter)
2008-10-29 04:40 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

I can see how i would do that with a static variable, but the variables that are accuatally arrays.. I don't know if that would work. IE. I could have any number of computers or users to skip, so i would have to read the file and assign them to an array is what i would think?

Indigo


Indigo
(Fresh Scripter)
2008-10-29 04:47 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Ok,

I reviewed your ini config layout, and i can see what ur saying.. it solves the issue that i was having when i would read my formatted Ini file and turning the values into an array. Via the following way:

What i was attempting to do was grab the headers, and then for each value under the header pull the exact piece of data... The problem with this is approach is i kept runing in to how do i transfer this into an array and pass the array back, so i can use it in my Script. When i tried to build a string i wansn't getting the results i wanted .. IE

 Code:
$_Data = $_Data + ReadProfileString(".\RS_Config.ini",PCNAME, $_Item) + ","


it Adds an additional "," which will cause an empty element in my array when i try spliting it via the "," Delimiter?

 Code:
$_Value = ReadProfileString(".\RS_Config.ini",PCNAME, '')
"Value: " + @CRLF + $_Value ?
$_aConfig = Split($_Value,Chr(10))

For Each $_Item in $_aConfig
	If Len(ltrim($_Item)) <> 0
		"Item: " + $_Item ? 
		$_Data = ReadProfileString(".\RS_Config.ini",PCNAME, $_Item)
	Else
		"Data: " $_Data ?
		Sleep 4
		Exit
	EndIf
Next


Ini file layout:

 Code:
[UTS]
Value1=data
Value2=data
Value3=data
Value4=data
Value5=data
Value6=data


I am assuming that i would just split the string that is pulled back using the delimiter "," to make an array which is how my script handles the computer to skip and users.



Indigo
(Fresh Scripter)
2008-10-29 04:57 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

DOH!!!

I just realized you did split the Readprofile string statment!!

Well thats what i get for not reading carefully hahah


Glenn BarnasAdministrator
(KiX Supporter)
2008-10-29 05:05 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Yup, and it's unlikely (given your struggles) that you'll forget it anytime soon! ;\)

Glenn


Indigo
(Fresh Scripter)
2008-10-29 05:52 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Well,

I have completed most of the changes, and everything as far as I can tell is in tip top shape.

I have not added the Prompting users for config info if the config file isn't found yet, but i will get to that next.

I also made it so the sytem acts more agressive and reboots systems where no one is logged in.. Why send a net message when I could reboot the system without impact to the user.

Here is Version .5
 Code:
; ===========================================================================================
;
;	Title:   Windows XP Reboot of network clients
;	Author:  Indigo			
;	Description:  Sends out emails at 7 Days, and Reboots at 10	
;	Version: .5
;
;	Special Thanks: Glenn, I wanted to say thanks for all the Key help when needed to overcome some hurdles in getting this script this far.
;
;	Revision Notes:
;
;	* I added the Ability to read from a config file.  The config file must remain in the location from where the script is called InI file is RS_Config.ini	
;	* I have also added some color to the Current Status Display, and I moved it to its own function.
;	* I also made the Script more agressive when it comes to users that arn't logged in, It will auto reboot those systems instead of sending text message.
;	* Note: the system will still do a Net Send Messages to the current system being proccess for any generic users that are defined in the Users to skip section. 
;
; ===========================================================================================

; == Seting Kixtart Options == 

$Rc = SetOption('Explicit', 'Off')
$Rc = SetOption('NoVarsInStrings', 'On')
$Rc = SetOption('NoMacrosInStrings', 'On')
$Rc = SetOption('WrapAtEOL', 'On')

Break on

; == Declaring Variables. == 

Dim $DontReboot		; == Systems that won't be rebooted
Dim $UserstoSkip	; == Users that will be skipped
Dim $EmailServer	; == The Hostname of the Email Server
Dim $EmailSufix		; == The "company.com" in the Email addresses
Dim $RS_Logs		; == The Log Location \\server\share\path\
Dim $IT_Email		; == The Administrator Email
Dim $Rc				; == Return Code for Kixtart Options
Dim $Computers		; == An Array that holds all the Computers Comnetview gathers
Dim $Computer		; == Each Compuer in Computers
Dim $Online			; == Systems Online / Not Online
Dim $Winver			; == Windows Version
Dim $WMICheck		; == WmiCheck pass/fail
Dim $Uptime			; == Uptime in Days IE. 10
Dim $Kixlib			; == Kix Library location


; == Intializing  Computer & User Special Consideration Veriables == ***** Variables below must be changed to needed Values ******

$CfgFile = @ScriptDir + "\RS_Config.ini"

$DontReboot  = Split(ReadProfileString($CfgFile, 'CONFIG', 'NoReboot'), ',')	; Computers to Be Skipped
$Userstoskip = Split(ReadProfileString($CfgFile, 'CONFIG', 'SkipUsers'), ',')	; Users to be Skipped
$EmailServer = ReadProfileString($CfgFile, 'CONFIG', 'EmailServer') 			; HostName of Email Server
$EmailSufix  = ReadProfileString($CfgFile, 'CONFIG', 'EmailSuffix')				; Sufix of Email Address Company.com

$RS_Logs = ReadProfileString($CfgFile, 'CONFIG', 'Logs')				; Don't use the trailing \ because it won't work right
$IT_Email = ReadProfileString($CfgFile, 'CONFIG', 'AdminEmail')			; Email Address of System Admin or Group
$Kixlib = 	ReadProfileString($CfgFile, 'CONFIG', 'Kixlib')				; Define Where your Kixtart Lib is here Do not place a trailing \

; === Includes all Udfs needed for this script ===

 Call $Kixlib + "\Comnetview.udf"
 Call $Kixlib + "\WmiUptime.udf"
 Call $Kixlib + "\Translatename.udf"
 Call $Kixlib + "\Ping.udf"
 Call $Kixlib + "\FnWMIloggedin.udf"
 Call $Kixlib + "\WMIConfirm.udf"

; == Clears Log Files If Script has been run before == 		    **********************************************************

del $RS_Logs + "\Systems_UpTime.txt"							
del $RS_Logs + "\Systems_Offline.txt"		

$computers = COMNetView()			; == Locates computers on the network 
CLS
For Each $computer in $computers											
	;$computer ?
	$online = Ping($computer,0,0,1)	; == Ping confirms computer online
	If $online = "1"														
		$winver = ReadValue("\\" + $computer + "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductName")
		If $winver = "Microsoft Windows XP" 								
			$WMICheck = WMIConfirm($computer)
				If $WMICheck <> 0										
					$UpTime = WMIuptime($computer)
					$Userloggedin = GetloginName($Computer)	
					
					
					DisplayInfo($Computer,$Winver,$Userloggedin,$Uptime); == This Function displays the current system info
					
					
					If len(ltrim($Uptime[0])) <> 0						; == Checks digit value of Uptime to see if it is 0 or not
						If Systemcheck($Computer,$DontReboot) = -1		; == Checks to make sure system isn't in the Protected list
							
							If $Uptime[0] >= 7
								If RedirectOutput ($RS_Logs + "\Systems_UpTime.txt") = 0 
									$Userloggedin = GetloginName($computer)	
									? $computer + "'s Uptime is: " + $Uptime[0] + " Days.  " + $Userloggedin ?
									$ = RedirectOutput("")
								EndIf 
							EndIf;
					
							Select
								Case $Uptime[0] >= 0 and $Uptime[0] < 7								

									If Exist ($RS_Logs + "\" + $computer + ".SentEmail.txt")
										"Email Tag File found Deleting .... < 7 " + @CRLF
										del $RS_Logs + "\"+ $computer + ".SentEmail.txt"
									Endif
									@CRLF
									
								Case $Uptime[0] >= 7 and $UpTime[0] < 10
									
									If $Userloggedin = "(User Not Logged In)"
										@CRLF + $Computer + " Is being rebooted.. Because no one is logged in." + @CRLF
										Shutdown ($computer, "This System Is Being Rebooted in 3 seconds....",3,1,1)
									Else	
										"System is being processed." + @CRLF
										WriteEmail($computer,$Uptime[0],$RS_Logs)			
										SendEmail($Userloggedin,$Computer,$Uptime[0],$EmailServer,$IT_Email,$EmailSufix,$RS_Logs,$Userstoskip,0)
									EndIf
								
								Case $Uptime[0] >= 10 										
									
									If Exist ($RS_Logs + "\" + $Computer + ".SentEmail.txt")
										@CRLF + $Computer + " Is being rebooted.." + @CRLF
										;Shutdown ($computer, "Please Save Your Work,  This System Is Being Rebooted in 1 min.",60,1,1)
									Else
										WriteEmail($computer,$Uptime[0],$RS_Logs)
										SendEmail($Userloggedin,$Computer,$Uptime[0],$EmailServer,$IT_Email,$EmailSufix,$RS_Logs,$Userstoskip,0)
									Endif
							
							Endselect
						Else
							@CRLF + "This System Is In The Protected List..(Skipping)" + @CRLF
						EndIf
					Else
					@CRLF +  "Uptime Check Failed!!! (Skipping & Logging)" + @CRLF + "Logfile: " + $RS_Logs + "\System_UptimeChck_Failed.txt" + @CRLF
						If RedirectOutput ($RS_Logs + "\System_UptimeChck_Failed.txt") = 0 
							"Uptime Check On: " + $computer + " Failed!!" + @CRLF
							$ = RedirectOutput("")
						EndIf
					EndIf
				Else
					$computer + " was skipped & Logged for review. WmiReturn Code: " + $WMICheck + @CRLF
					If RedirectOutput ($RS_Logs + "\Errorlog.txt") = 0 
						$computer + "'s Error Code is " + @error + " - " + @SERROR + @CRLF
						"This system was skipped & Logged for review. WmiReturn Code: " + $WMICheck + @CRLF
						$ = RedirectOutput("")
					EndIf 
				Endif
		EndIf
	Else
		If RedirectOutput ($RS_Logs + "\Systems_Offline.txt") = 0 
			$computer + @CRLF
			$ = RedirectOutput("")
		EndIf
	Endif
Next
; ----- System Reboot Email with attached System Uptimes Log -----
	
	SendEmail($Userloggedin,$Computer,$Uptime[0],$EmailServer,$IT_Email,$EmailSufix,$RS_Logs,$Userstoskip,1)

; ================== Functions Below This Point ====================

; ----- This function displays on the screen the current system information. --
Function DisplayInfo($_Computer,$_Winver,$_Userloggedin,$_Uptime)
	
	CLS
	color m+/n
	"System"color c+/n": " color g+/n  $_Computer color m+/n " ("color c+/n"Online" color m+/n  ")" + @CRLF
	"OS"color c+/n": "color g+/n  $_Winver + @CRLF
	color m+/n
	"User"color c+/n": " color g+/n $_Userloggedin + @CRLF
	color m+/n
	"Uptime"color c+/n": " color g+/n  $_Uptime[0]  color c+/n " Days" + @CRLF color w+/n 

EndFunction

;----- This function just checks to make sure we don't reboot a pc that needs to stay up. --
Function Systemcheck($_Chkcomputer,$_DontReboot)		

; == Declaring Variables
Dim $_Result		; Holds the Result of the calculation
Dim $_Chkcomputer	; Computer to be checked
Dim $_DontReboot 	; Global Variable Transfered to Function.

	$_Result = 0
	$_Chkcomputer = TRIM(LCASE($_Chkcomputer))					
	$_Result = Ascan($_DontReboot,$_Chkcomputer,0)				
	$Systemcheck = $_Result										

EndFunction

; ---- Removes invalid email users ----
Function checkusers($_Users,$_Userstoskip)		

; == Declaring Variables
Dim $_Result		; Holds the Result of the calculation
Dim $_Chkuser		; User to be checked
Dim $_Users			; User passed to function (raw)
Dim $_Userstoskip 	; Global Variable Transfered to Function.

	$_Result = 0
	$_Chkuser = TRIM(LCASE($_Users))					
	$_Result = Ascan($_Userstoskip,$_Chkuser,0)				
	$checkusers = $_Result
	
EndFunction

;----- Pulls in the user that is logged into X machine  ----------------------------
Function GetloginName($_Chkcomputers)

; == Declaring Variables
Dim $_Usrloggedin	; User Logged into current system in current format Domain\Username
Dim $_Usrname		; Just username by itself

$_Usrname = Split(fnWMILoggedIn(1,$_Chkcomputers), '\')[1] ; Extracts the username out of Domain\user to be just User.

If len(ltrim($_Usrname)) = 0	; == Checks for a 0 digit value assigned to user, if it did (User not logged) in is Returned.
	$_Unli = "(User Not Logged In)"
	$Getloginname = $_Unli
	Return
Endif

$Getloginname = $_Usrname

EndFunction


;----- Sends an email to the user whos system has been up for more than 7 days, and sends email to administrator.
Function SendEmail($_User,$_System,$_Systemup,$_EmailServer,$_IT_Email,$_EmailSufix,$_RS_Logs,$_Userstoskip,$_AdminEmail)
; == Declaring Variables
Dim $_User			; User to be emailed
Dim $_System		; Hostname of current system
Dim $_Systemup		; Uptime of Current system
Dim $_Unli			; Defined as (User Not Logged In) - Incase user isn't logged in
Dim $_EmailSufix 	; Global Variable Transfered to Function.
Dim $_IT_Email 		; Global Variable Transfered to Function.
Dim $_RS_log		; Global Variable Transfered to Function.
Dim $_Email			; Building Block Variable for Sending Emails.
Dim $_NetSend		; Building Block of the NetSend Message.
					; Through a Variable for On/Off maybe setup a Debug Admin Feature, so only admin is emailed

$_Email = 'bmail'
$_Email = $_Email + ' -s '
$_Email = $_Email + $_EmailServer
$_Email = $_Email + ' -f ' + $_IT_Email	
	
	If $_AdminEmail = 1
		$_Email = $_Email + ' -t ' + $_IT_Email
		$_Email = $_Email + ' -a ' + '"Systems That need to be rebooted"'
		$_Email = $_Email + ' -m ' + $_RS_Logs + '\Systems_uptime.txt'
	Else
		$_Email = $_Email + ' -t ' + $_User
		$_Email = $_Email + ' -a ' + '"(System Reboot Needed!) Uptime: ' + $_Systemup + ' Days."'
		$_Email = $_Email + ' -m ' + $_RS_Logs + '\' + $_System + '.SentEmail.txt'
	EndIf

$_NetSend = 'net send '
$_NetSend = $_NetSend + $_System
$_NetSend = $_NetSend + ' "Reboot Notice: This system has been turned on for ' 
$_NetSend = $_NetSend + $_Systemup
$_NetSend = $_NetSend + ' days please reboot!, Thanks IT"'


If checkusers($_User,$_Userstoskip) = -1		; Makes sure certian users don't get emails.
	"Sending Email..." + @CRLF
	Shell $_Email
Else
	"Sending Net Send Message..." + @CRLF
	Shell $_NetSend
Endif

EndFunction


;----- Writes the email file that is included in the body of the email sent. ------------
Function WriteEmail($_Computer,$_Uptime,$_RS_Logs)

"Writing Log File.." + @CRLF

; == Declaring Variables
Dim $_Computer 		; Hostname of Current System
Dim $_Uptime		; Uptime of Current System
Dim $_RS_Logs		; Handles Log locations

	If RedirectOutput ($_RS_Logs + "\"+ $_Computer + ".SentEmail.txt",1) = 0  ; == Creates a Log File to indicate the sending of an email.
		@CRLF $_Computer + "'s Uptime is: " + $_Uptime + " Days."	
		@CRLF
		@CRLF "This is the Body of the Email that will be sent... Fill it in with whatever you want."
		@CRLF
		$ = RedirectOutput("")
	EndIf 

EndFunction


Indigo
(Fresh Scripter)
2008-10-30 04:23 PM
Re: Hi, All - (Where do i Post a Full Script I want to Share)

Just a FYI, i have posted an update to the the Script. its at V.6 now haha ;\)