0

我有一个问题,我从这个应用程序启动了一个具有管理员权限的应用程序,最后启动了另一个应用程序。然后继承管理员权限。但它应该从正常的用户权限开始。有没有人有解决问题的方法或提示?

4

1 回答 1

0

最简单的方法是让 Explorer 为您启动它:

Process.Start("explorer.exe", """C:\path to\your.exe""")

您不能将任何参数传递给 exe - exe 名称已经是资源管理器的参数,我不相信有办法让资源管理器将您作为参数(给资源管理器)提供的其余内容解释为“应该传递给正在启动的程序”..

..但是您可以创建一个传递相关参数的小程序,然后资源管理器启动该小程序。

'this is literally all the mini program does, then quits:
Process.Start("myactualprogram.exe", "some fixed arguments")

你的主要提升程序会:

Process.Start("explorer.exe", """C:\path to\miniprogram.exe""")

--

“但如果争论并不总是固定的呢?” Process.Start("myactualprogram.exe", "varying arguments here")我听到你哭了..“当我只能按名称启动它时,我怎样才能让我的小程序正常运行?”

好吧..您可以让您的实际程序通过TCP套接字或其他方式联系您的第一个程序并询问它的信息-进程间通信..或者可以编写一个文件,其中包含您的实际程序可以获取的参数..或者如果参数足够简单,您可以重命名(或复制)小程序,使其名称中包含参数,并且在启动时可以解析自己的名称

'myactualprogram.exe is expecting args of: varying arguments here
'the launcher is a winforms app called 'varying arguments here.exe' that has this code
Dim args = Path.GetFilenameWithoutExtension(Application.ExecutablePath)
Process.Start("myactualprogram", args)

Of course, if your program is expecting args like /out=c:\temp\file.txt then you'll have to get a lot more creative with itbecause you can't put / \ : in filenames.. how about base64 encoding the entire arg string, naming the file that, then having your launcher program decode the b64?

于 2021-08-20T09:35:27.513 回答