I am creating a small application to "RunAs different user". Files (Full path) which should be opened are stored in a Listview.
If call the procedure with Do_RunAs("C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.EXE", "D:\Run As Test\Naming - Test.xlsx") ... it is working
But If call the procedure with Call Do_RunAs("C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.EXE", item.SubItems(1).Text) I get this message in EXCEL (see linked picture) ...file is locked for editing by another user
Here is the code for Do_RunAs
Public Sub Do_RunAs(strApplication As String, strFilename As String)
Dim procStartInfo As New ProcessStartInfo
Dim procExecuting As New Process
With procStartInfo
.UseShellExecute = False
.Domain = strDomain
.UserName = strUserName
.Password = ConvertToSecureString(strPassword)
.Verb = "runas"
.LoadUserProfile = True
.FileName = GetShortPathName(strApplication)
.Arguments = GetShortPathName(strFilename).ToString
.WindowStyle = ProcessWindowStyle.Normal
End With
procExecuting = Process.Start(procStartInfo)
procExecuting.Close()
End Sub
As Arguments I already tried
- .Arguments = strFilename
- .Arguments = Chr(34) + strFilename + Chr(34)
- .Arguments = GetShortPathName(strFilename)
- .Arguments = GetShortPathName(strFilename).ToString
Nothing works, always the same error.
Would be great if someone could help me - Thanks a lot in advance!