MSFN Forum: batch get hostname supress 7th caracters... - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

batch get hostname supress 7th caracters... Rate Topic: -----

#1 User is offline   Mr.J!M 

  • Junior
  • Pip
  • Group: Members
  • Posts: 70
  • Joined: 25-March 04

Posted 28 May 2010 - 03:46 AM

Helloo!!!

i would like to make a BATCH or a VBS which get the HOSTNAME, supress ALL the caracters after the 7th and to add AB at the end...
also i would like to connect a drive to it:

net use o: \\XXXXXXXAB\folder$

is it possible?


#2 User is offline   arwidmark 

  • Member
  • PipPip
  • Group: Members
  • Posts: 102
  • Joined: 22-December 05
  • OS:none specified
  • Country: Country Flag

Posted 28 May 2010 - 04:32 AM

It depends on if you want to use the computername or the hostname (they are normally the same) though)

Here is a vbscript using the computername (run using cscript scriptname.vbs)

' get computer name

Set oWshShell = CreateObject( "WScript.Shell" )
Set oWshNetwork = WScript.CreateObject( "WScript.Network" )
sComputerName = oWshNetwork.ComputerName

sCmd = "net use O: \\" & Left(sComputerName,7) & "AB\folder$"

wscript.echo "Executing commandline: " & sCmd

oWshShell.run sCmd,0,True



Here is a vbscript using the hostname from registry (run using cscript scriptname.vbs)

' get hostname

Set oWshShell = CreateObject( "WScript.Shell" )
sRegValue = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname"
sHostName = oWshShell.RegRead( sRegValue )

sCmd = "net use O: \\" & Left(sHostName,7) & "AB\folder$"

wscript.echo "Executing commandline: " & sCmd

oWshShell.run sCmd,0,True


#3 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,363
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 28 May 2010 - 06:35 AM

Using Windows Command Script
Example.cmd
@ECHO OFF&SETLOCAL
(SET H_=)
FOR /F %%# IN ('HOSTNAME') DO (SET H_=%%#)
IF DEFINED H_ (NET USE O: \\%H_:~,7%AB\folder$)


#4 User is offline   Mr.J!M 

  • Junior
  • Pip
  • Group: Members
  • Posts: 70
  • Joined: 25-March 04

Posted 28 May 2010 - 04:23 PM

thanks so much adwidmark and Yzöwl!

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy