vb.net启动进程作为不同用户Excel 2013文档作为ListView的参数-文件已锁定
我正在创建一个小应用程序来“作为不同的用户运行”。应打开的文件(完整路径)存储在Listview中 如果调用该过程,请使用 Do_RunAs(“C:\ProgramFiles(x86)\Microsoft Office\Office15\EXCEL.EXE”,“D:\RunAs Test\Naming-Test.xlsx”) ... 它正在工作 但是 如果调用该过程,请使用 调用Do\u RunAs(“C:\Program Files(x86)\Microsoft Office\Office15\EXCEL.EXE”,item.SubItems(1.Text) 我在EXCEL中收到此消息(参见链接图片) 下面是Do_RunAs的代码vb.net启动进程作为不同用户Excel 2013文档作为ListView的参数-文件已锁定,excel,vb.net,listview,Excel,Vb.net,Listview,我正在创建一个小应用程序来“作为不同的用户运行”。应打开的文件(完整路径)存储在Listview中 如果调用该过程,请使用 Do_RunAs(“C:\ProgramFiles(x86)\Microsoft Office\Office15\EXCEL.EXE”,“D:\RunAs Test\Naming-Test.xlsx”) ... 它正在工作 但是 如果调用该过程,请使用 调用Do\u RunAs(“C:\Program Files(x86)\Microsoft Office\Office15
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
我已经试过了
- .Arguments=strFilename
- .Arguments=Chr(34)+strFilename+Chr(34)
- .Arguments=GetShortPathName(strFilename)
- .Arguments=GetShortPathName(strFilename).ToString
如果有人能帮助我,那就太好了——提前多谢了 我找到了那个问题的答案。。。也许有人需要它 在For Next循环中调用了此Sub。我只是在下次调用这个Sub之前添加了一个WAIT函数
For i = 1 To 10
Call Do_RunAs("Excel.exe", "xy.xls")
Wait(3) 'wait 3 seconds
Next
这就解决了问题