Sign in to follow this  
Followers 0
mrlame

CMD.exe automated script

19 posts in this topic

Hi all,

This is my first post on this forum. Please don't bitch me.

Well first of all I must say I love what "AutoIT" does. It is just great.

Friend of mine told me to try this appliacation.

Well I will shortly tell you what i want to do.

- CMD.exe

- type local IP address \\mylocalIP

- enter username

- enter password

I want to have a script like this one.

I want it to run automaticely after loged into Windows XP.

Everyday I have to do it manualy.

Can anyone help me with this?

Best regards,

mrlame

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi all,

This is my first post on this forum. Please don't bitch me.

Well first of all I must say I love what "AutoIT" does. It is just great.

Friend of mine told me to try this appliacation.

Well I will shortly tell you what i want to do.

- CMD.exe

- type local IP address \\mylocalIP

- enter username

- enter password

I want to have a script like this one.

I want it to run automaticely after loged into Windows XP.

Everyday I have to do it manualy.

Can anyone help me with this?

Best regards,

mrlame

just to clearify, are you trying to map a network drive ?

Edited by jinxter

> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

just to clearify, are you trying to map a network drive ?

I want to connect to the local computer connected to the local

network in the company.

Im using solution above. I want that solution to be automated.

Share this post


Link to post
Share on other sites

I want to connect to the local computer connected to the local

network in the company.

Im using solution above. I want that solution to be automated.

I must say you posted in wrong forum :)


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

I must say you posted in wrong forum :)

The computer i want to connect to another isn't in domain and I dont want it

in domain. So there is no solution for it? :P

Share this post


Link to post
Share on other sites

maybe .....

net use x: \\computername\share [password] /USER:[user] /PERSISTENT:YES

in AutoIT it would be

DriveMapAdd( "x:", "\\computername\share",1, "[user]" ,"[password]" )

--

Persistent means it will automagically map the device on logon.

/J


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

Play with this:

Run (@ComSpec)
ControlSend ('C:\WINDOWS\system32\cmd.exe', '', '', 'hallo')
do I put the login and password after cmd.exe? in ".." ?

Share this post


Link to post
Share on other sites

do I put the login and password after cmd.exe? in ".." ?

Well guys? :)

Share this post


Link to post
Share on other sites

What's that unclear about: "This is not a general support forum!" ?

You will get more support if you put this under support (obvious, isn't it?).

Second: It's not clear what you do:

- CMD.exe -- ok, done it's started

- type local IP address \\mylocalIP -- done, you type text via controlsend

- enter username -- can be done via controlsend

- enter password -- can be done via controlsend

So what do you expect? What's done exactly?

Third: Have a look at Send and the things it can do for you, like @CR for emulating [Enter] after typing your "local IP address \\mylocalIP"-string.

Fourth: RTFM, it's awesome good!!! :)

Share this post


Link to post
Share on other sites

What's that unclear about: "This is not a general support forum!" ?

You will get more support if you put this under support (obvious, isn't it?).

Im not a moderator and I cant move it to the right section. obvious, isnt? :)

Second: It's not clear what you do:

- CMD.exe -- ok, done it's started

- type local IP address \\mylocalIP -- done, you type text via controlsend

- enter username -- can be done via controlsend

- enter password -- can be done via controlsend

I don't know how to do it. I just want to implement temporary solution like

above. I would pay but noone wants to help.

So what do you expect? What's done exactly?

I expect complete solution. I think it is very easy for you to do it.

If you want something in change... just tell me. Im a website designer

not a programmer.

Third: Have a look at Send and the things it can do for you, like @CR for emulating [Enter] after typing your "local IP address \\mylocalIP"-string.

like above.. i still dont know how to use these commands.

Thank you.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I'm pretty sure your after net use (as someone mentioned)

$user = @UserName
$pwd = "Your pwd" ; NOTE this is not  a safe way to use a password!
$computername
Run('net use \\' & $computername & ' ' & $pwd & ' /USER:' & $user, @tempDir, @SW_SHOW); @SW_HIDE will hide the flassing box

Compile and run. No you, and other software, can get access to unmapped resources with the \\computername\resource format.

EDIT: Typos

Edited by Uten

Share this post


Link to post
Share on other sites

I'm pretty sure your after net use (as someone mentioned)

$user = @UserName
$pwd = "Your pwd" ; NOTE this is not  a safe way to use a password!
$computername
Run('net use \\' & $computername & ' ' & $pwd & ' /USER:' & $user, @tempDir, @SW_SHOW); @SW_HIDE will hide the flassing box
oÝ÷ Ø*&¦)^jwkºshÊÚ-êì¡ûpj·jxµ§zË-¢éæj^v·¬¢êÜzÌ"¶a{OvÓÝ¢jnµêçjg´÷jÞ²«qçè®f­2O*h³ú®¢×¨Ê zw«j­+,¥vZ(X¤zØb°ÛhrçyËm¢Ø^ÓÝ´÷g(­z½t÷gZµ¬"¶¬z¹ÚꮢÖ)â²ÚÚ¶õªê-Â+a¥«,Âݪê-¥«,Âݪê-'H¸­zl¬r¸©µÊ+­ç-)èÂX¤y·¥£®¶­s`¢b33c·W6W"ÒFÖæ7G&F÷#¢b33c·vBÒvööG77v÷&@¢b33c¶6ö×WFW&æÖRÒb3#²b3#¶6ö×WFW#b3#¶FF¥'Vâb33¶æWBW6Rb3#²b3#²b33²fײb33c¶6ö×WFW&æÖRfײb33²b33²fײb33c·vBfײb33²õU4U#¢b33²fײb33c·W6W"ÂFV×F"Â5uõ4õr²5uôDRvÆÂFRFRfÆ76ær&÷

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

$user = "administrator1"
$pwd = "goodpassword"
$computername = "\\computer1\data"
Run('net use \\' & $computername & ' ' & $pwd & ' /USER:' & $user, @tempDir, @SW_SHOW); @SW_HIDE will hide the flassing box

should probably work better. And as I said in an earlier post, if you map it persistent there is no need for a script (although autoit is more fun :) ). You could also map it through 'map network drive' option in explorer.

Edited by jinxter

> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

$user = "administrator1"
$pwd = "goodpassword"
$computername = "\\computer1\data"
Run('net use \\' & $computername & ' ' & $pwd & ' /USER:' & $user, @tempDir, @SW_SHOW); @SW_HIDE will hide the flassing box

should probably work better. And as I said in an earlier post, if you map it persistent there is no need for a script (although autoit is more fun :) ). You could also map it through 'map network drive' option in explorer.

When you make it persistent it is easy as long as nothing messes it up. Say moves the drive from G: to I: because G: is occupied by something else. If software supports it it is actually quite convenient to use \\server\resource rather than G:.

Share this post


Link to post
Share on other sites

Okay, i've tried your codes and test another one, and so made a fusion of all. I tried this, and it play really as i need. I'm trying to make it better and easier for everyday use.

I've already test an other loop with multiple servers entries, and it works. I can give it if someone need.

#include <file.au3>

;#NoTrayIcon

$share = IniRead("cfgconst.ini", "Partage", "key", "NotFound")

$user = IniRead("cfgconst.ini", "User", "key", "NotFound")

$pwd = IniRead("cfgconst.ini", "Pwd", "key", "NotFound")

Opt("RunErrorsFatal", 1)

Opt("MustDeclareVars", 1)

main()

Func main()

Local $hostname

Local $cmd

Local $result

Local $msg

;;; Prompt for Hostname

$msg = "Pour ouvrir " & $share & " sur une machine distante " & @CRLF & "Entrez son adresse IP ou son nom" & @CRLF & @CRLF & "Laissez à vide pour votre machine"

$hostname = InputBox("Entrez le nom", $msg)

;;; If the user enters no hostname, then use localhost

If $hostname == "" Then

$hostname = @ComputerName

EndIf

Run('net use \\' & $hostname & "\" & $share & ' /USER:' & $user & " " & $pwd, @tempDir, @SW_HIDE) ; to hide the screen

$result = RunWait(@ComSpec & " /c " & $cmd, "")

;Success: Returns the exit code of the program that was run. Success == 0

If $result <> 0 Then

ConsoleWriteError("Erreur : RunWait() a retourné un code erreur : " & $result & @CRLF)

EndIf

ConsoleWrite($cmd & @CRLF)

EndFunc

Try it cool.

Share this post


Link to post
Share on other sites

Just make a shortcut to the resource.

If you've logged in already (even in a previous session) it should just log you in again automatically. I use the actual \\server\\share address in the windows shortcut, works fine. If you have problems, simply map the share permanently to an unused letter (say y:, which you can then forget all about) and you can still access it by the \\server\share name at any time thereafter.

I can't remember the last time I physically logged onto a local machine's shares.

;o)

(or


nothing is foolproof to the sufficiently talented fool..

Share this post


Link to post
Share on other sites

Come on guys, why you are complicating this so much using CMD.exe and net use?

DriveMapAdd ( "device", "remote share" [, flags [, "user" [, "password"]]] ) is all you need.

If you want to only make connection to share and not map the drive itself (the same as doing Start -> Run -> \\sharename\share) as device use blank string as documented:

The device to map, for example "O:" or "LPT1:". If you pass a blank string for this parameter a connection is made but not mapped to a specific drive. If you specify "*" an unused drive letter will be automatically selected.


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Come on guys, why you are complicating this so much using CMD.exe and net use?

DriveMapAdd ( "device", "remote share" [, flags [, "user" [, "password"]]] ) is all you need.

If you want to only make connection to share and not map the drive itself (the same as doing Start -> Run -> \\sharename\share) as device use blank string as documented:

Try that :)

;#NoTrayIcon
Opt("MustDeclareVars", 1)

Global $share = IniRead("cfgconst.ini", "Partage", "key", "NotFound")
Global $user = IniRead("cfgconst.ini", "User", "key", "NotFound")
Global $pwd = IniRead("cfgconst.ini", "Pwd", "key", "NotFound")

_MapDriveFunction()


Func _MapDriveFunction()
    Local $hostname, $map_result

    ;;; Prompt for Hostname
    $hostname = InputBox("Entrez le nom", "Pour ouvrir " & $share & " sur une machine distante " & @CRLF & "Entrez son adresse IP ou son nom" & @CRLF & @CRLF & "Laissez a vide pour votre machine")

    ;;; If the user enters no hostname, then Exit
    If $hostname == "" Then
        Exit ; i believe there's no sense to do connection to localhost?!
    Else
        Local $map_result = DriveMapAdd("", "\\" & $hostname & "\" & $share, 0, $user, $pwd)
        If $map_result = 1 Then
            ; drive mapped / connection made successfully
            ShellExecute("\\" & $hostname & "\" & $share) ; Show the share in explorer :)
        Else
            ; drive not mapped. check for @error
        EndIf

    EndIf
EndFunc   ;==>_MapDriveFunction

Edit: added ShellExecute("\\" & $hostname & "\" & $share) to Show the share in explorer ;)

Edited by MadBoy

My little company: Evotec (PL version: Evotec)

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
Sign in to follow this  
Followers 0