Page 1 of 4 1234>
Topic Options
#190175 - 2008-10-20 06:44 PM Client Reboot Script / Sends out Email warnings) Version .6
Indigo Offline
Fresh Scripter
**

Registered: 2008-10-01
Posts: 34
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


Edited by Indigo (2008-10-30 04:24 PM)

Top
#190176 - 2008-10-20 07:21 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Indigo]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190177 - 2008-10-20 09:00 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Glenn Barnas]
Indigo Offline
Fresh Scripter
**

Registered: 2008-10-01
Posts: 34
Alright,

I sent you a PM.

Indigo

Top
#190178 - 2008-10-20 09:04 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Glenn Barnas]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ofcourse you can always post it in scripts forum...
_________________________
!

download KiXnet

Top
#190179 - 2008-10-20 09:08 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Lonkero]
Indigo Offline
Fresh Scripter
**

Registered: 2008-10-01
Posts: 34
Is that ok?

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

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

Registered: 2008-10-01
Posts: 34
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 


Edited by Indigo (2008-10-20 09:44 PM)

Top
#190181 - 2008-10-20 09:19 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Indigo]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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. \:\)
_________________________
!

download KiXnet

Top
#190182 - 2008-10-20 09:21 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Lonkero]
Indigo Offline
Fresh Scripter
**

Registered: 2008-10-01
Posts: 34
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

Top
#190189 - 2008-10-21 12:47 AM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Indigo]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190190 - 2008-10-21 12:53 AM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190191 - 2008-10-21 01:39 AM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Indigo]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
 


Edited by Lonkero (2008-10-22 09:11 PM)
Edit Reason: LONG LINE POLICE
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190192 - 2008-10-21 02:12 AM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190194 - 2008-10-21 02:38 AM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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.

Top
#190195 - 2008-10-21 04:12 AM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190214 - 2008-10-21 03:55 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Glenn Barnas]
Indigo Offline
Fresh Scripter
**

Registered: 2008-10-01
Posts: 34
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.

Top
#190215 - 2008-10-21 04:02 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Indigo]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
For this, just CLS and prompt for input - I would not get fancy at this point, as there are only 5 parameters.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190217 - 2008-10-21 04:46 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Glenn Barnas]
Indigo Offline
Fresh Scripter
**

Registered: 2008-10-01
Posts: 34
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.

Top
#190218 - 2008-10-21 05:11 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Indigo]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190224 - 2008-10-21 08:09 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Glenn Barnas]
Indigo Offline
Fresh Scripter
**

Registered: 2008-10-01
Posts: 34
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?

Top
#190226 - 2008-10-21 09:03 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Indigo]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 4 1234>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 340 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.075 seconds in which 0.024 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org