【发布时间】:2019-10-09 19:40:22
【问题描述】:
所以我创建了一个 GUI,它使用模拟和 powershell 命令激活和停用网络适配器。
这是代码中的一个sn-p:
Get_adapters 获取所有适配器并将它们绑定到列表视图:
public MainWindow()
{
InitializeComponent();
Get_adapters();
}
这是我的两个按钮命令:
private void Activate_interface(object sender, RoutedEventArgs e)
{
string interface_name = ((Netadapter)ListView.SelectedItem).Name;
Change_adapter_status(true, interface_name);
}
private void Deactivate_interface(object sender, RoutedEventArgs e)
{
string interface_name = ((Netadapter)ListView.SelectedItem).Name;
Change_adapter_status(false, interface_name);
}
这是 powershell 方法:(隐藏了帐户凭据;但我已经检查了多次,它们都是正确的)。
public void Change_adapter_status(bool _option, string _interface)
{
using (new Impersonator("Administrator", "DOMAIN", "pw"))
{
var process_info = new ProcessStartInfo();
process_info.FileName = @"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe";
process_info.Verb = "runas";
if (_option == true)
{
process_info.Arguments = String.Format("netsh interface set interface „{0}“ enable", _interface);
}
else if (_option == false)
{
process_info.Arguments = String.Format("netsh interface set interface „{0}“ disable", _interface);
}
Process.Start(process_info);
}
}
如您所见,我使用模拟以管理员用户身份启动 powershell 窗口。
在我的机器上 (Admin acc) 一切正常。单击按钮,powershell 窗口打开并执行其操作。
在其他计算机上(非管理员但在同一个域中,并且可以使用上面代码中的凭据访问管理员帐户),exe 甚至都不会启动。
计算机具有相同的图像(Windows 10)并且目标 .net 框架也是正确的。
在其他管理员帐户上,exe 是可执行的。那么它可能是什么 exe不会为非管理员用户启动?提前谢谢。
事件输出: - 系统
-
提供者
[名称] .NET 运行时
-
事件 ID 1026
[限定符] 0
2级
任务 0
关键字 0x80000000000000
-
创建时间
[系统时间] 2019-05-23T10:01:14.748998500Z
事件记录 ID 6679
渠道申请
计算机 PLMC12906.greencorps.intra
安全
- 事件数据
应用程序:Adapter.exe 框架版本:v4.0.30319 描述:进程因未处理的异常而终止。获取信息:System.Runtime.InteropServices.COMException 来自 System.Management.MTAHelper.CreateInMTA(System.Type) 来自 System.Management.ManagementPath.CreateWbemPath(System.String) 来自 System.Management.ManagementPath..cctor() TypeInitializationException bei System.Management.ManagementScope._Clone(System.Management.ManagementScope, System.Management.IdentifierChangedEventHandler) bei System.Management.ManagementObjectSearcher..ctor(System.Management.ManagementScope, System.Management.ObjectQuery, System.Management.EnumerationOptions) bei System.Management.ManagementObjectSearcher..ctor(System.Management.ObjectQuery) bei Adapter.MainWindow.Get_adapters() bei Adapter.MainWindow..ctor() Ausnahmeinformationen: System.Windows.Markup.XamlParseException bei System.Windows.Markup.WpfXamlLoader .Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri) 在 System.Windows.Ma rkup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri) 在 System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows .Markup.ParserContext, System.Object, Boolean) bei System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext) bei System.Windows.Application.LoadComponent(System.Uri, Boolean) bei System.Windows.Application.DoStartup() 贝 System.Windows.Application.<.ctor>b__1_0(System.Object) 贝 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) 贝 系统。 Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) 来自 System.Windows.Threading.DispatcherOperation.InvokeImpl() 来自 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System .Object) bei MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object) b ei System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 北 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System. Object, Boolean) bei System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) bei MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object) 贝 System.Windows.Threading.DispatcherOperation.Invoke() 贝 System.Windows.Threading.Dispatcher.ProcessQueue() 贝 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)在 MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) 在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System. ○ bject, Int32) 在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) 在 System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading. DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) 在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr) 在 MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef ) 北 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 北 System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) 北 System.Windows.Application.RunDispatcher(System.对象)bei System.Windows.Application.RunInternal(System.Windows.Window) bei System.Windows.Application.Run(System.Windows.Window) bei System.Windows.Application.Run() bei Adapter.App.Main()
【问题讨论】:
标签: c# admin impersonation