Hi,
I'm trying to execute a cmd file with a different user but what I have isn't working the log in returns true but the command doesn't run
vb Code:
Dim iu As New ImpersonateUser ' Note: This user must be the user that installed ReaConverter Pro otherwise each image ' will be stampted with a ReaConverter logo. This is a limitation of the evaluation/trial version. ' impersonateValidUser(username, domain, password) If iu.impersonateValidUser("myusername", "mydomain", "mypassword") = True Then Call cFunctions.WriteToFile("Impersonating user succeeded!", False, Application("LogFilePath"), Application("LogFile")) Try ' Execute the command ' http://stackoverflow.com/questions/206323/how-to-execute-command-line-in-c-get-std-out-results Dim oProcess As System.Diagnostics.Process = New System.Diagnostics.Process Dim strCmd As String = sOutputFolderPath.Replace("\pdf", "") & "ReaConvertFile.cmd" ' path and file name of command to run With oProcess .StartInfo.FileName = strCmd .StartInfo.UseShellExecute = False .StartInfo.RedirectStandardInput = True .StartInfo.RedirectStandardOutput = True ' Start the process .Start() Dim strOutput As String = .StandardOutput.ReadToEnd ' Wait for process to finish oProcess.WaitForExit(2000) '5000 If .HasExited = False Then .Kill() .Close() End With sFN = System.IO.Path.GetFileNameWithoutExtension(sFilePath) sFilePath = System.IO.Path.Combine(sOutputFolderPath.Replace("\pdf", ""), sFN & ".jpg") 'Call cFunctions.SendMail(Server.MachineName & " - Success converted image to JPG", "Converted image to JPG: \\" & Server.MachineName & "\" & sFilePath.Replace(":", "") & vbNewLine, sSupportEmails, sSupportNames, "[email protected]", "PDF Conversion Service") Call cFunctions.WriteToFile("Success converted image to JPG: " & sFilePath & vbNewLine) Catch ex As Exception Call cFunctions.SendMail(Server.MachineName & " - Failed to convert image to JPG", "File path: \\" & Server.MachineName & "\" & sFilePath.Replace(":", "") & vbNewLine & ex.Message & vbNewLine & ex.StackTrace & vbNewLine, sSupportEmails, sSupportNames, "[email protected]", "PDF Conversion Service") Call cFunctions.WriteToFile("Failed to convert image to JPG" & vbNewLine & "File path: " & sFilePath & vbNewLine & ex.Message & vbNewLine & ex.StackTrace & vbNewLine, False, Application("LogFilePath"), Application("LogFile")) End Try ' Finish Impersonating here iu.undoImpersonation() Else Call cFunctions.SendMail(Server.MachineName & " - Failed to impersonate user", "Error: converting image to JPG - failed to impersonate user!" & vbNewLine & vbNewLine & "File path: \\" & Server.MachineName & "\" & sFilePath.Replace(":", "") & vbNewLine, sSupportEmails, sSupportNames, "[email protected]", "PDF Conversion Service") Call cFunctions.WriteToFile("Failed to impersonate user" & vbNewLine & "Error: converting image to JPG - failed to impersonate user!" & vbNewLine & "File path: " & sFilePath, False, Application("LogFilePath"), Application("LogFile")) End If
If I remove the impersonation stuff the command executes but my images are stamped with the coversion tools logo which is a limitation of the trial version. The image conversion tool needs to be run by the user that installed and registered it. I'm confident that the impersonation works as I use this class to copy files accross the network in other areas of my applicaiton.
The command file is also okay because if I manually run the command file (ReaConvertFile.cmd) the image file is converted.
I know that the licence is installed correctly because if I log into the server as the relevant user and run the conversion tool manually (through the GUI or manually execute the .cmd file) the files convert and are not stamped with the conversion tools logo.
I think something is missing the correct permissions? I tried giving my user full control of ...\system32\cmd.exe but that didn't help????
Any thoughts or ideas will be greatly appreciated.




Reply With Quote