Net use Command : Windows CE - batch-file

I'm trying to send network credentials using Net Use command.
This is what I have:
#echo off
net use \\<serverName>\<shareFolder>\ passw0rd /USER:domain.com\UserName
PAUSE
This automatically inserts the username and Domain but for some reason not the password!!
I have tried it like this as well:
#echo off
net use \\<serverName>\<shareFolder>\ /USER:domain.com\UserName passw0rd
PAUSE
I have checked the paths I'm using and they definitely work. When i copy them out and paste in RUN they work.
Same goes for the username and passwords.
Everything in google search is purple cause I've clicked on all the links :/
Ok, I thought I had it...
I tried it like this:
#echo off
net use \\<serverName>\<shareFolder>\ <mapName> /USER:domain.com\UserName passw0rd
PAUSE
And it worked, but only because i entered the password before i tried it like this and then it remembered the password.
So I'm still looking for a way.
Please help.

Does the password contain special characters like % / ~ or similar characters with special meaning in batch files?
Yes, then enclose the password in double quotes.
Use also double quotes around UNC path and test if that makes a difference.
What I miss in all your net use commands is the device name usually specified left of UNC path to shared folder to map the shared folder to a drive letter. Therefore it could be that the password is interpreted as device name.
But according to your question you want to pass only the user credentials and password to be able to access the shared folder using UNC path. However, I suggest to test if it makes a difference really mapping the shared folder to a drive letter. I don't know if the password string is interpreted as device name if no device name specified and can't test it by myself at the moment.

#echo off
net use <MapDriveName> \\<serverName>\<ShareFolder>\ /PASSWORD:<Passw0rd> /USER:<UserName>
PAUSE
This one works for me. Finally :)
Hope this can help someone else as well.

net use Y: \server_name OR ipaddress\shared /user:domainname\%username%

Related

How to write a full path in a batch file having a username with spaces?

Essentially I am referencing a path in my batch file that includes the username.
Here is what I mean:
C:/users/%username%/
Using %username% does seem to work when refrecning the user currently logged in to the machine, but fails if the username has a space. For example the username jlows works no problem, but j lowes does not and shows an error saying user "j" cannot be found.
What can be added to the path to account for this situation?
Always quote paths in batch files. This way, it helps you in order to avoid misbehaviours like this one. In most of the cases, system considers, e.g. the path random which doesn't exist because you have entered random test.
So, replacing / with \ as this is the default Windows separator, will give you:
"C:\Users\%username%"
However, there is a shorter version, userprofile, which stands for C:\Users\%username%, exactly what you have. Use it like:
"%UserProfile%"

Batch file to delete all *.auc files in %LOCALAPPDATA% for a specified user?

Is there a way to build a batch file to delete all *.auc files in %LOCALAPPDATA% for a specified user. Like maybe to have it ask for a username and then use that as the target for the delete function?
I tried to look around but couldn't figure out a way to do it with both the wildcard and a specified user. In all fairness I am pretty new at this. We have users who pretty regularly have to delete these files, while we are troubleshooting the underlying cause, it would be nice to simplify this process as much as possible.
Try something like below (not TESTED though but should work fine)
#echo off
set /p uname="Enter user ID: "
set path_firstpart = "C:\Users\"
set path_secondpart = "\AppData\Local"
set pathtodeletein = %path_firstpart%%uname%%path_secondpart%
del "%pathtodeletein%\*.auc" /S /Q
If you want to provide this batch for the current user you can use %LOCALAPPDATA% as the path to delete in or use %username% in order to avoid asking for the username.
If you want more fancy user interaction you could switch to windows scripting host and vbscript (phew ...) which allows you to open input boxes.

BAT file programming assistance : how to make a response in a bat file copy to another part OR to clipboard?

My apologies if the title was confusing. It should be fairly basic, but I cannot find a way to do this.
What i'm wanting to do is have a bat file prompt for an answer to a question and then surround that answer with another piece of code and either copy to the clipboard or after the connection.
Maybe it will make more sense if i give the code.
#echo off
set /p input ="what server would you like to connect to? (example srv02) :"
echo Myhome.%input%.com
pause
c:\program files\putty
the echo gives the correct response, but i would like to see if there is a way to paste this past the c:\program files\putty to connect to a server.
OR if there is a way to copy that response to the clipboard so the bat file would open putty (which it does now) and then you could just paste that response.
Or am i going about this the wrong way? thanks for the help!!
I'm not a PuTTY user, so I can't be sure - But I believe you are simply trying to pass the the server host that you want to connect to. I think the following will do what you asked:
"c:\program files\putty" %input%
or
"c:\program files\putty" Myhome.%input%.com
However, there are probably other command line options you need to really accomplish your goal.
You should learn the PuTTY command line arguments and options. I suspect a web search could find some tutorials or examples to get you started.
Perfect! That is what i ended up doing after a few more hours of research.
I came up with two different types of scripts as my company wants us to use a specific set of defaults for different servers.
#echo off
set /p input="what server would you like to connect to? : "
echo myhome.%input%.com| clip
echo ----
echo myhome.%input%.com has been copied to your clipboard,
echo you can now paste into the host name box in putty
echo -----
echo Press enter to open puTTY
echo -----
Pause
start c:\users\public\apps\putty.exe
Ended setting it to open putty instead of pasting because it should be defaulted settings, but not everyone kept it that way, of course.
Thanks for the assistance though!

Stop Batch file if its being run from a drive

Hi I want to stop a batch file if it is being run from a particular drive. I have tried somehting like this, it doesn't work though. I would appreciate it if someone has a better idea.
if %CD%=="^.*C:\" (goto :CDrive)
Where :CDrive is an error message saying that the user is trying to run it from the wrong drive.
Cheers
Chris
You can use a substring to check:
if "%CD:~0,2%"=="C:" goto CDrive
Another option might be that you just explicitly set the drive you're expecting:
pushd X:
or use full paths instead of relative ones.

Batch file to map a drive when the folder name contains spaces

I am trying to map a drive using a batch file.
I have tried:
net use m: \\Server01\myfolder /USER:mynetwork\Administrator "Mypassword" /persistent:yes
It works fine. The problem comes when I try to map a folder with spaces on its name:
net use m: \\Server01\my folder /USER:mynetwork\Administrator "Mypassword" /persistent:yes
I have tried using quotes, using myfold~1 but nothing works.
An easy way would be renaming the folder but I have it mapped in more than 300 workstations so is not a very good idea.
I just created some directories, shared them and mapped using:
net use y: "\\mycomputername\folder with spaces"
So this solution gets "works on my machine" certificate. What error code do you get?
whenever you deal with spaces in filenames, use quotes
net use "m:\Server01\my folder" /USER:mynetwork\Administrator "Mypassword" /persistent:yes
I'm not sure this will help you to much by I once needed a batch file to open a game, the .exe was in a folder with blanks (duh!) and I tried : START "C:\Fold 1\fold 2\game.exe" and START C:\Fold 1\fold 2\game.exe - None worked, then I tried
START C:\"Fold 1"\"fold 2"\game.exe and it worked
Hope it helps :)
net use "m:\Server01\my folder" /USER:mynetwork\Administrator "Mypassword" /persistent:yes
does not work?
net use f: \\\VFServer"\HQ Publications" /persistent:yes
Note that the first quotation mark goes before the leading \ and the second goes after the end of the folder name.

Resources