Search code examples
filebatch-fileini

Batch file that opens an ini file with username and password credentials


I am trying to open an ini file on a remote machine with.....

start notepad \\%IP%\c\%path%\filename.ini

The problem I have is that it needs a windows username and password.

When I browse to \192.168.1.X\ it requires me to login, which I can. I need the batch file to be able to do this as well.

I will also need to copy a few other files to that IP to a few different locations.


Solution

  • You could try mapping the share with the net command:

    net use R: \\%IP%\c %password% /USER:%username%
    if errorlevel 1 goto :eof
    start notepad R:\%path%\filename.ini
    

    When you are finished you can run:

    net use R: /DELETE
    

    The only thing I'm concerned about here is that because you're using the start command, you can't clean up the mapped drive, otherwise it might disappear before notepad can open the file. And you wouldn't be able to save it.

    Perhaps you would consider splitting this into a script that sets up a mapping and another script that does the required actions.

    For more information, type:

    net help use