开发者

Get computer name and/or full network file path

开发者 https://www.devze.com 2023-01-07 11:20 出处:网络
Using Scripting.FileSystemObject I can get the full path name of a file, but this will always be like \"c:\\tem开发者_StackOverflow社区p\\myfile.txt\". How can I get the name of the PC, or a network-p

Using Scripting.FileSystemObject I can get the full path name of a file, but this will always be like "c:\tem开发者_StackOverflow社区p\myfile.txt". How can I get the name of the PC, or a network-path to the file like \MyPC\temp\myfile.txt? Is there another class other than Scripting.FileSystemObject I can use?


Set wshNetwork = WScript.CreateObject( "WScript.Network" )
strComputerName = wshNetwork.ComputerName
WScript.Echo "Computer Name: " & strComputerName

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


This is a single line answer that is equivalent to Chris's answer

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

精彩评论

暂无评论...
验证码 换一张
取 消