Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 



Mr.J!M

batch get hostname supress 7th caracters...

Recommended 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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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$)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

×