how are you? I have a problem with credentials, I do not know how to pass password and user in a bat file. Please read the context.
I have created a windows service, that takes some configuration values from a bat file, using the args parameter.This service writes a txt file in the desired location, but Here you are some basic code of my windows service:
static void Main(string[] args)
{ //args comes from the bat file
CmdLineArgs cmdArgs = new CmdLineArgs(args);
//pass the values for mydirectory from args
AppConfig.NetworkDirectory = cmdArgs.GetArg("/mydirectory");
writefile(AppConfig.NetworkDirectory,"text for file");
if(couldntwriteinpath())
{ //...manage error
}
}
The writefile procedure:
//this is a very simple way of doing this, so you can have an idea of what is going on
public static void writefile(string path, string text)
{ string savepathname=path+"\myfile.txt";
//uses the class File.writealltext function
File.WriteAllText(savepathname, text);
}
The bat file :
cd C:\Windows\System32
sc.exe stop MyService
sc.exe delete MyService
timeout 3
sc.exe create MyService binPath="\"C:\apps\MyService\MyService.exe\" /mydirectory"\\192.168.90.x\homes\writefolder\"" start= auto
sc.exe start MyService
PAUSE
**The problem is that I receive an error: "The user name or password is incorrect".
Can you help me? I tried to do all stackoverflow answers like https://stackoverflow.com/questions/3854026/how-to-give-credentials-in-a-batch-script-that-copies-files-to-a-network-locatio,https://stackoverflow.com/questions/303045/connecting-to-a-network-folder-with-username-password-in-powershell, etc.. but did not work.
I want to insert the user and password in the bat. So, when calling the File.WriteAllText procedure, it takes the credentials also.
Thanks