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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript/%computername%

Status
Not open for further replies.

Briandr

MIS
Jul 11, 2003
177
US
Hi,

Google once again proved to be of no help. So I am hoping someone can help me out with something I think is easy.

Const Hidden=0
Const WaitonReturn=True
Dim FSO
Set FSO=CreateObject("Scripting.FileSystemObject")
set objNetwork=CreateObject("Wscript.Network")
Set WshShell=CreateObject("Wscript.Shell")
strComputerName = wshShell.ExpandEnvironmentStrings
wshshell.CurrentDirectory="c:\windows\"
FSO.CopyFile "c:\windows\windowsxp-kb936929-sp3-x86-enu.log", "c:\%computername%.txt"
Set FSO=nothing

What I want is when executing FSO.CopyFile is to have a file created using the actual computername (i.e, Mycomputer.txt). It is not working. Do I need to do read/write with the vb code? Can you give me as example? I just don't know how to code this. Thanks!
 
[0] Since you instantiate wscript.network and wscript.shell, either one can get you the strComputerName if you do it correctly.
[tt]
strComputerName=wshShell.ExpandEnvironmentStrings[red]("%computername%")[/red]
'or
strComputerName=objNetwork.computername
[/tt]
[1]
>FSO.CopyFile "c:\windows\windowsxp-kb936929-sp3-x86-enu.log", "c:\%computername%.txt"
[tt]FSO.CopyFile "c:\windows\windowsxp-kb936929-sp3-x86-enu.log", "c:\[red]" & strComputerName & "[/red].txt"[/tt]
 
Hi Guys,

I'd like to take this one step further. Every time the script gets run and the log file gets copied, could an e-mail be sent out? Nothing fancy. Just looking for a way to track when a file gets copied over. Thanks.
 
You can use a function like the snippet below:
Code:
Function sendMail (mailSubject,mailBody)
    Set objEmail = CreateObject("CDO.Message")
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objShell = WScript.CreateObject ("WScript.Shell") 
    computerName = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
    userName = objShell.ExpandEnvironmentStrings("%USERNAME%")
    objEmail.From = "whoever@whoever.com"
    objEmail.To = "them@them.com"
    objEmail.Subject = mailSubject
    objEmail.Textbody = mailBody
    objEmail.Configuration.Fields.Item _
        ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
    objEmail.Configuration.Fields.Item _
        ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = _
        "your.smtp.server." 
    objEmail.Configuration.Fields.Item _
        ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top