Computername escribe en un archivo txt (% computername%)

If a computer run's the script on Wednesday, i want that it creates a %computername*.txt file in a netwok map. In batch script i can to it with %computername%.txt, what code can i use it for VBS script?


Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

If DatePart("W",Date) = 4 Then
    'Today is Wednesday, so run the virus scan
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile("\\server\Avast Scan Log\%COMPUTERNAME%.txt")
    WshShell.Run """C:\Program Files\Alwil Software\Avast4\aswcmd"" M: /m /*", , True
End If 

preguntado el 09 de marzo de 12 a las 14:03

2 Respuestas

>> WScript.Echo CreateObject("WScript.Shell").ExpandEnvironmentStrings("%COMPUTERNAME%")
>>
WINXPSP3
>> WScript.Echo CreateObject("WScript.Network").Computername
>>
WINXPSP3

respondido 09 mar '12, 14:03

Hi, Tnx for your reply. It doesn't work. It is just showing the Computername in Window. I just want it to create %computername%.txt file on network location. We have 50 computers here. Every computers must write their own computername to their own txt file. Like com1.txt, com2.txt, com3.txt etc. - e2e2

Come on, what about incorporating the returned computername into your script by loading it into a variable and using that variable in the filename you create with objFSO.CreateTextFile? We are here to help you, not to spell out every line of code until it works. - Caos automatizado

Use the WshNetwork object to get the computer name as suggested. It looks like this.

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
strComputer = WshNetwork.ComputerName

If DatePart("W",Date) = 4 Then
    'Today is Wednesday, so run the virus scan
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile("\\server\Avast Scan Log\" & strComputer & ".txt")
    WshShell.Run """C:\Program Files\Alwil Software\Avast4\aswcmd"" M: /m /*", , True
End If

respondido 09 mar '12, 21:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.