Mr.J!M

batch get hostname supress 7th caracters...

4 posts in this topic

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?

0

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

0

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

0

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.