一个程序也许会被多个用户运行,如下:
那在VB.NET的WinForm环境下,怎样获取User Name呢?
可从下面的方法:
代码:
Public Shared Function GetProcessOwner(ByVal ProcessName As String) As String Dim po = String.Empty Dim selectQuery As SelectQuery = New SelectQuery("Win32_Process") Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(selectQuery) Dim moc As ManagementObjectCollection = searcher.Get() For Each proc As ManagementObject In moc Dim s(1) As String proc.InvokeMethod("GetOwner", CType(s, Object())) If proc("Name").ToString() = ProcessName & ".exe" Then po = s(1) & "\\" & s(0) End If Next Return po End Function
View Code
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦