PDA

View Full Version : Getting PC name and making file (W2K)



mcslemon
06-27-2002, 03:49 PM
I know how to get the computer name, and how to echo it on the screen. Is there a way of taking that name and then making a file....say 3119 and making file 3119.id ?

Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Domain Name: " & WshNetwork.UserDomain

^ that echos the domain name

LRNGlnx
06-27-2002, 04:03 PM
> Set WshNetwork = WScript.CreateObject("WScript.Network")

> WScript.Echo "Domain Name: " & WshNetwork.UserDomain

WARNING: I am not a Win Scripter, but I do know some programming.

In your example you used 3119 to 3119.id
Would something like this suit your needs?

WScript.Echo "Domain Name: " & WshNetwork.UserDomain & ".id"

Only substitute WScript.Echo with something to create a variable. Then there should be a way to create a file using that variable name.

mcslemon
06-27-2002, 04:31 PM
yeah, thats pretty much what Ive done...I just need the command for creating a file. I would also like the reverse, to delete it once its used. not in the same code thou :D

Jama
06-27-2002, 06:20 PM
Option Explicit
Dim WshNetwork, fName1, fName2, fileName, fso, f1, f2, WshShell
Set WshNetwork = WScript.CreateObject("WScript.Network")

' Set up the file name and path.
fName1 = WshNetwork.ComputerName & " - " & WshNetwork.UserName
fName2 = "c:\test\"
fileName = fName2 & fName1 & ".id"
'fileName is now = "C:\test\ComputerName - UserName.id"

' Create the file and add data to it.
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile(fileName, True)
f1.WriteLine "Hello world!"
f1.WriteBlankLines(2)
f1.WriteLine "Computer Name: " & WshNetwork.ComputerName
f1.WriteLine "User Name: " & WshNetwork.UserName
f1.WriteBlankLines(2)
f1.WriteLine "file Name: " & fileName
f1.close

' Open the file with Notepad.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run "notepad" & " " & fileName, 1, True

' Show file details, then delete it.
Set f2 = fso.GetFile(fileName)
WScript.Echo "About to delete:" & vbNewline & vbNewline & f2.Path
f2.Delete

' Release objects.
Set WshNetwork = Nothing
Set fso = Nothing
Set f1 = Nothing
Set f2 = Nothing
Set WshShell = Nothing
' Done.

Jama

mcslemon
06-28-2002, 09:12 AM
what can I say....????

THANK YOU!! STAR! ahahaha