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

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

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

Checking for the existence of an application 1

Status
Not open for further replies.

OregonITFella

IS-IT--Management
Jun 4, 2004
17
0
0
US
I need some help with a little project I dreamed up (gotta love those). I want a login script to check each users machine that logs in and see if a particular application exists on the machine, and then emails me the machine name, username and if the application is installed or not. Can anyone start me out with some code to get me going? Below is what I have that I would like to use.

Code:
'=====================================
 
Dim oName, oUserName, ODomain, oMyIP, oTo

' Get the computer name
Set WshNetwork = CreateObject("WScript.Network")
oName = WshNetwork.ComputerName

' Get the username
Set WshNetwork = CreateObject("WScript.Network")
oUserName = WshNetwork.Username

' Set the company specific information

' Company Internet Domain Name
ODomain = "xxxxx.xxx"
' Set the SMTP server IP
oMyIP = "xxx.xxx.xxx.xxx" 
' Where do you want the message to be delivered
oTo = "xxx@xxxxx.xxx"


' Set the visual basic constants as they do not exist within VBScript.
' Do Not set your smtp server information here.
Const cdoSendUsingMethod = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing",[/URL] _
cdoSendUsingPort = 2, _
cdoSMTPServer = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver"[/URL]

'// Create the CDO connections.
Dim iMsg, iConf, Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

'// SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort

'// Set the SMTP server address here.
.Item(cdoSMTPServer) = oMyIP
.Update
End With

'// Set the message properties.
With iMsg
Set .Configuration = iConf
.To = oTo
.From = oName & "@" & oDomain
.Subject = "Username and Machine Name"
.TextBody = "Machine " & oName & " at company " & ODomain & " is being used by " & oUsername
End With

'// An attachment can be included.
'iMsg.AddAttachment Attachment

'Send the message.
iMsg.Send 

MsgBox "Done"
 
I solved this problem. I guess I know more than I thought.

 
Oops! I spoke too soon. The problem I am still having is that I cannot define the variable to the windows system folder (WinXP). I have tried this code:

Code:
Set FSys = CreateObject("Scripting.FileSystemObject")
If Not FSys.FileExists("%SYSTEMROOT%\file1.exe") Then
oAppInstalled = "Was Not Found"
Else
oAppInstalled = "Was Found"
End If

But this returns Was Not Found in the email regardless if the file is located there or not, so I am assuming that the path %SYSTEMROOT% is not the correct variable. Is this correct to check at the windows root folder for the file1.exe in question?

Thanks for any help.
 
set WshShell = WScript.CreateObject("WScript.Shell")
strSystemDir = WshShell.Environment("SYSTEMROOT")

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I ended up using this:

Code:
Set FSys = CreateObject("Scripting.FileSystemObject")
if Not FSys.FileExists(FSys.GetSpecialFolder(0) & "\file1.exe") Then
oAppInstalled = "Was Not Found"
Else
oAppInstalled = "Was Found"
End If

I am creating another version of this with this code:

Code:
Set FSys = CreateObject("Scripting.FileSystemObject")
If Not FSys.FileExists("C:\test.html") Then
oAppInstalled = "File Not Found"
Else
oAppInstalled = "File Found"
End If

What I need to know now is how would I recursively check the C drive (or any drive I want) for this file (or whatever file I wanted)?
 
try a WMI file search. you can specify wild cards and it should return a collection of files matching those criteria. havent got an example to hand but i am sure if you search this forum you will find an example. might be quicker than recursively looping through all folders using FSO
 
Not to confuse the issue, but here is another potential way to search for a file recursively that is relatively fast. This will show you every .vbs file on your harddrive:
Code:
Option Explicit
Dim oExec
Dim strOut
Dim oWsh:Set oWsh = CreateObject("WScript.Shell")
Set oExec = oWsh.Exec("cmd /c Dir /s c:\*.vbs")
Do While oExec.Status = 0
	If Not oExec.StdOut.AtEndOfStream Then
		strOut = strOut & oExec.StdOut.Read(1)
	End If
Loop
WScript.Echo strOut

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top