Page 3 of 4 <1234>
Topic Options
#190288 - 2008-10-23 06:16 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Kdyer]
Indigo Offline
Fresh Scripter
**

Registered: 2008-10-01
Posts: 34
I am unfamilar with WMI ... is there any good docs on how to use it?

Indigo

Top
#190289 - 2008-10-23 06:53 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Indigo]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

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

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

Top
#190295 - 2008-10-23 09:39 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
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190325 - 2008-10-27 04:13 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
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!!!


Edited by Indigo (2008-10-27 04:20 PM)

Top
#190326 - 2008-10-27 04:21 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
While i am here,

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

Indigo

Top
#190327 - 2008-10-27 04:25 PM Re: Hi, All - (Where do i Post a Full Script I want to Share) [Re: Indigo]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#190328 - 2008-10-27 04:32 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
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190330 - 2008-10-27 04:34 PM 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
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190332 - 2008-10-27 04:41 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
Thanks! Glenn

I will see what I can come up with.

Top
#190353 - 2008-10-28 08:06 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
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


Top
#190354 - 2008-10-28 08:14 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
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190355 - 2008-10-28 08:24 PM 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 - 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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190356 - 2008-10-28 10:03 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
ok, just maybe I'm stupid, but...

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

download KiXnet

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

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

Top
#190367 - 2008-10-29 04:40 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 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

Top
#190368 - 2008-10-29 04:47 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
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.



Edited by Indigo (2008-10-29 04:53 PM)

Top
#190369 - 2008-10-29 04:57 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
DOH!!!

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

Well thats what i get for not reading carefully hahah

Top
#190370 - 2008-10-29 05:05 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
Yup, and it's unlikely (given your struggles) that you'll forget it anytime soon! ;\)

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

Top
#190371 - 2008-10-29 05:52 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
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

Top
Page 3 of 4 <1234>


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

Who's Online
1 registered (Allen) and 303 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.076 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