I have written a simple piece of code to try and copy the WebCacheV01.dat file from the Edge Browser, as the fille is locked I am using the VSS commands to do this.
When I run the command manually, from an elevated prompt, it copies the database without any issue. When I try to replicate the command using C#, it errors.
VSS Subsystem Init failed, 0x80042302 Operation terminated with error
-2403 (JET_errOSSnapshotNotAllowed, OS Shadow copy not allowed (backup or recovery in progress)) after 0.47 seconds.
I have run the debugging, line by line and the arguments are correct. I just can't get around the error message.
using (var cmdEsentutl = new Process())
{
cmdEsentutl.StartInfo.FileName = "esentutl";
cmdEsentutl.StartInfo.UseShellExecute = false;
cmdEsentutl.StartInfo.CreateNoWindow = false;
//cmdEsentutl.StartInfo.Arguments = $#"/y /vss {GlobalVariables.edge44HistoryDB}\WebCacheV01.dat /d E:\WebCacheV01.dat";
cmdEsentutl.StartInfo.Arguments = $#"/y {GlobalVariables.edge44HistoryDB}\WebCacheV01.dat /vssrec V01 . /d F:\WebCacheV01.dat";
cmdEsentutl.StartInfo.Verb = "runas";
cmdEsentutl.StartInfo.RedirectStandardError = true;
cmdEsentutl.Start();
cmdEsentutl.WaitForExit();
}
Related
I've got a dotnet core 6 project where I need to execute SSIS packages via dtexec.
So far I have the following code:
private void ExecutePackage()
{
var processOutput = string.Empty;
var processErrorOutput = string.Empty;
var command = #"/C dtexec /file ""C:\git\star\tests\Star.Shared.UnitTests\test-artifacts\TestPackage.dtsx""";
var process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = command;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
processOutput = process.StandardOutput.ReadToEndAsync().Result;
processErrorOutput = process.StandardError.ReadToEndAsync().Result;
if (processOutput != string.Empty)
{
_logger.LogInformation("{output}", processOutput);
}
if (processErrorOutput != string.Empty)
_logger.LogError("{errors}", processErrorOutput);
}
When running this via my unit test, it just seems to hang and I'm unsure as to why.
On one of my previous attempts to get this file to run I got the following message:
An error occurred trying to start process 'dtexec /file "C:\git\star\tests\Star.Shared.UnitTests\test-artifacts\Test_Package.dtsx' with working directory 'C:\git\star\tests\Star.Shared.UnitTests\bin\Debug\net6.0'. The system cannot find the file specified.
Which is telling me that the last time I ran this, it was looking in my tests bin folder for the package instead of where the package is stored.
Is there a setting that I'm missing / set wrong?
Im making an application which needs to monitor the filesystem using FileSystemWatcher, to detect how an installation affects the filesystem.
To get rid of noise i want to filter the events that are created by their creating user, and that code is working with the //BUILTIN //Administrator user, which is used by default when doing an installation. But still there are quite a bit of noise. Then i got the idea of creating a specific user that i can use for running the installation file, and filter on that specific user, and thereby getting rid of allmost all the noise.
this is my code for the process creation and start
private void executeInnoInstaller(string path, string fileName)
{
// Use ProcessStartInfo class
ProcessStartInfo installerProces = new ProcessStartInfo();
installerProces.CreateNoWindow = true;
installerProces.UseShellExecute = false;
installerProces.FileName = path + "\"" + fileName + "\"";
installerProces.WindowStyle = ProcessWindowStyle.Normal;
installerProces.UserName = "test";
System.Security.SecureString encPassword = new System.Security.SecureString();
foreach (System.Char c in "test")
{
encPassword.AppendChar(c);
}
encPassword.MakeReadOnly();
installerProces.Password = encPassword;
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(installerProces))
{
exeProcess.WaitForExit();
//int exitCode = exeProcess.ExitCode;
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
this code exits with a access denied.
OS=Windows
Ive already tried to run the installer.exe from the OS filehandler with SHIFT - Rightclick using the specified user, and it works.
VisualStudio is run as administrator.
Ive tried to run the build project exe file as administrator, but it does not work.
Without the user credentials, the code works and uses the //BUILTIN //Administrator account
Does anybody have any idea ?
Thank you beforehand for your time and effort.
This code works if i turn down the UAC securitylevel to the lowest.
I need to execute this command on our remote Skype server:
SEFAUtil.exe /server:lyncserver.domain1.co.uk sip:MySelf#domain.com /addteammember:sip:OtherUser#domain.com /delayringteam:10
which adds a colleague to my team call group.
I am able to run the command on the server itself, and the code below works when sending other commands to that server:
var processToRun = new[] { process };
var connection = new ConnectionOptions();
var wmiScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", LyncServer), connection);
var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
var reason = wmiProcess.InvokeMethod("Create", processToRun);
However, when process is the string:
"cmd /c cd /d C:\\Program Files\\Microsoft Lync Server 2013\\ResKit && SEFAUtil.exe /server:lyncserver.domain1.co.uk sip:MySelf#domain.com /addteammember:sip:OtherUser#domain.com /delayringteam:10"
Then the user is not added to the team call group.
I can see that reason contains the uint 0, which usually indicates success - but the actual command is clearly failing.
I also tried adding > C:\users\user.name\desktop\output.txt and 2> C:\users\user.name\desktop\output.txt to the end of the command, but they just created empty text files, so not very useful!
Update
I tried changing the command to the following:
const string LyncServer = "server.domain1.co.uk";
const string ResKitPath = #"C:\Program Files\Microsoft Lync Server 2013\ResKit";
var command = "SEFAUtil.exe /server:{LyncServer} sip:MySelf#domain.com /addteammember:sip:OtherUser#domain.com /delayringteam:10";
var process = $"cmd /c cd /d \"{ResKitPath}\" && {command}";
So that the path containing spaces is double-quoted and the slashes are not being escaped, but with the same results.
Does anyone know of another way of debugging this or retrieving the output for the newly created process?
I've had a similar issue, mine was that the command shell needed to run elevated. SEFA is a bit naff at giving good error messages, and fails silently.
Below is the code for running the batch file from the command prompt. The problem is that there is a pause command in the batch file which is stopping the application and I am not able to proceed with the next step. Can some one give me an idea to fix this.
Process gacCOMprocess = new Process();
infoPageExecuteBatchFiles.PageText = "Running gacCOM.bat ";
infoPageExecuteBatchFiles.Refresh();
ProcessStartInfo gacCOMprocessStartInfo = new ProcessStartInfo();
gacCOMprocessStartInfo.FileName = PRES_TIER_PATH + "\\gacCOM.bat ";
gacCOMprocessStartInfo.UseShellExecute = false;
gacCOMprocessStartInfo.RedirectStandardOutput = true;
gacCOMprocessStartInfo.CreateNoWindow = true;
gacCOMprocessStartInfo.RedirectStandardInput = true;
gacCOMprocess.StartInfo = gacCOMprocessStartInfo;
gacCOMprocess.OutputDataReceived += new DataReceivedEventHandler(ExecuteBatchFilesHandler);
gacCOMprocess.Start();
gacCOMprocess.BeginOutputReadLine();
gacCOMprocess.WaitForExit();
gacCOMprocess.Close();
You could just add a parameter that you can pass along with the command line when you start the program. Then add a check for this parameter to each pause.
That's what i did recently (assuming you can edit the batch file):
Set IsAutomated=%1
IF NOT %IsAutomated%==1 (
echo Script was started manually.
pause
)
That was because the script was still also run manually and in that case, the pause was needed.
I'm receiving an output error while trying to redirect a process input from a file - reading the file content and writing it to the process input.
the error: <output file> The volume for a file has been externally altered so that the opened file is no longer valid.
the code:
*before foreach loop:
prc = new Process();
prc.StartInfo.FileName = prcs;
prc.StartInfo.UseShellExecute = false;
*inside foreachloop:
prc = new Process();
prc.StartInfo.FileName = prcs;
prc.StartInfo.UseShellExecute = false;
if (prcs == asProcesses[0])//first process - only redirect output
{
prc.StartInfo.RedirectStandardInput = true;
prc.StartInfo.RedirectStandardOutput = true;
prc.Start();
sw = prc.StandardInput;
StreamReader sr1 = new StreamReader(sInRedirect);
while ((outputLine = sr1.ReadLine()) != null)
{
sw.Write(outputLine);
sw.WriteLine();
}
sr = prc.StandardOutput;
}
* i get the message while writing the command: "text1.txt < sort"
another thing, if i run the program in another computer i get the message:
" the pipe is being closed"
thank you for your help!
It seems that the permission on your output directory are set in a way that prevents Visual Studio from compiling.
Remove any read-only flags from the project's folder and all subdirectories, clear the output folder and, if necessary, take ownership of the folders or give yourself full permissions.
Source: msdn - Visual Studio 2010 fails to build or debug reports error 'Failed to write to output file'.