VBScript - get the computer name and / or the full path to the network file

Using Scripting.FileSystemObject , I can get the full path name of the file, but it will always look like "c: \ temp \ myfile.txt". How can I get the PC name or network path to a file, for example \ MyPC \ temp \ myfile.txt? Is there another class other than Scripting.FileSystemObject that I can use?

+7
vbscript
source share
2 answers
 Set wshNetwork = WScript.CreateObject( "WScript.Network" ) strComputerName = wshNetwork.ComputerName WScript.Echo "Computer Name: " & strComputerName 

Source: http://www.robvanderwoude.com/vbstech_network_names_computer.php :

+10
source share

This is a one line response equivalent to Chris's answer.

 WScript.Echo CreateObject("WScript.Network").ComputerName 
0
source share

All Articles