Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

batch get hostname supress 7th caracters...

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Mr.J!M

Mr.J!M

    Junior

  • Member
  • Pip
  • 70 posts
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?


How to remove advertisement from MSFN

#2
arwidmark

arwidmark

    Member

  • Member
  • PipPip
  • 105 posts
  • OS:none specified
  • Country: Country Flag
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

Regards

Johan Arwidmark
Microsoft MVP - Setup / Deployment

#3
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,534 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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
Mr.J!M

Mr.J!M

    Junior

  • Member
  • Pip
  • 70 posts
thanks so much adwidmark and Yzöwl!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN