小编Sco*_*ain的帖子

从不使用标签控件的对话框中获取文本?

这是我之前的问题的延续.如何抑制Inproc COM服务器显示的对话框.


背景:

回顾一下我的情况:我有一个从第三方用Delphi编写的Inproc COM服务器.如果它捕获特定类型的错误,我调用的函数之一将显示错误消息对话框.问题是我正在尝试批量处理数据,我正在使用的数据源导致错误对话框弹出很多(感谢我之前的问题的答案它现在自动关闭,我能够运行它到完成后,它会显示对话框并要求有人按OK 9923次).进程将阻塞,直到消息框关闭.


题:

我想更好地记录错误对话框所说的内容.但是,任何获取对话框正文的尝试都失败了.

对话框的图像

//Snip

private void StartWindowListener()
{
    //Queue the watcher on the message pump if we are not watching.
    if (_watcherRunning == false)
    {
        _watcherRunning = true;
        _dummyForm.BeginInvoke(new Action(() =>
        {
            _watcherRunning = false;

            //If we are not inside the com object don't enumerate.
            if (_insideCom == false) return;

            // Enumerate windows to find dialogs
            EnumThreadWndProc callback = new EnumThreadWndProc(CheckWindow);
            EnumThreadWindows(GetCurrentThreadId(), callback, IntPtr.Zero);
            GC.KeepAlive(callback);
        }));
    }
}

private bool CheckWindow(IntPtr hWnd, IntPtr …
Run Code Online (Sandbox Code Playgroud)

c# delphi winapi messagebox

12
推荐指数
1
解决办法
3411
查看次数

为什么return和throws语句的顺序会导致有关无法访问代码的不同警告

private static ext.clsPassageiro ConversaoPassageiro(ncl.clsPassageiro clsPassageiro)
{
     ext.clsPassageiro _result = new ext.clsPassageiro();
     throw new NotImplementedException();
     return _result;
}
Run Code Online (Sandbox Code Playgroud)

显示"检测到无法访问的代码" return _result;,

private static ext.clsPassageiro ConversaoPassageiro(ncl.clsPassageiro clsPassageiro)
{
    ext.clsPassageiro _result = new ext.clsPassageiro();
    return _result;
    throw new NotImplementedException();
}
Run Code Online (Sandbox Code Playgroud)

没有显示"检测到无法访问的代码" throw new NotImplementedException();,

为什么第二种情况没有显示警告?

.net c#

12
推荐指数
0
解决办法
117
查看次数

算法计算不同类型的内存

我正在努力计算记忆力.我使用以下代码计算了Available,InUse,Free和Cached

  ObjectQuery wql = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(wql);
            ManagementObjectCollection results = searcher.Get();

            //total amount of free physical memory in bytes
            var Available = new ComputerInfo().AvailablePhysicalMemory;
            //total amount of physical memory in bytes
            var Total = new ComputerInfo().TotalPhysicalMemory;

            var PhysicalMemoryInUse = Total - Available;
            Object Free = new object();
            foreach (var result in results)
            {
                //Free amount
                Free = result["FreePhysicalMemory"];
            } 
            var Cached = Total - PhysicalMemoryInUse - UInt64.Parse(Free.ToString());
Run Code Online (Sandbox Code Playgroud)

如何计算Windows中资源监视器中显示的待机,硬件保留和修改内存?

在此输入图像描述

c#

12
推荐指数
1
解决办法
600
查看次数

当dns或netbios不可用时,如何通过网络模拟用户的文件副本

可能重复:
在C#中访问Windows中受密码保护的网络驱动器?

我在DomainA上运行ComputerA作为userA需要将一个非常大的文件复制到WorkgroupB上的ComputerB,其中ip为192.168.10.2到只有userB具有写访问权限的Windows共享.

没有netbios或dns解析因此必须通过IP来修复计算机

我先试试

AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);
WindowsIdentity UserB = new WindowsIdentity("192.168.10.2\\UserB", "PasswordB"); //Execption
WindowsImpersonationContext contex = UserB.Impersonate()
File.Copy(@"d:\bigfile", @"\\192.168.10.2\bifgile");
contex.Undo();
Run Code Online (Sandbox Code Playgroud)

但我得到一个System.Security.SecurityException"提供的名称不是一个正确形成的帐户名称."

所以我试过了

AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);
WindowsIdentity webinfinty = new WindowsIdentity("ComputerB\\UserB", "PasswordB"); //Execption
Run Code Online (Sandbox Code Playgroud)

但我得到"登录失败:未知的用户名或密码错误." 而是错误.

所以我试过

IntPtr token;
bool succeded = LogonUser("UserB", "192.168.10.2", "PasswordB", LogonTypes.Network, LogonProviders.Default, out token);
if (!succeded)
{
     throw new Win32Exception(Marshal.GetLastWin32Error());
}
WindowsImpersonationContext contex = WindowsIdentity.Impersonate(token);
(...)
[DllImport("advapi32.dll", SetLastError = true)]
static extern bool LogonUser(
      string principal,
      string authority,
      string password,
      LogonTypes logonType,
      LogonProviders logonProvider,
      out IntPtr token); …
Run Code Online (Sandbox Code Playgroud)

c# impersonation

11
推荐指数
1
解决办法
3万
查看次数

如何使程序不显示在Alt-Tab或任务栏上

我有一个需要坐在后台的程序,当用户连接到RDP会话时,它会进行一些环境设置,然后启动一个程序.当程序关闭时,它将执行一些内务处理并注销会话.

我目前的做法是让终端服务器启动这个应用程序.这是作为Windows窗体应用程序构建的,以防止控制台窗口出现:

public static void Main()
{
    //(Snip...) Do some setup work

    Process proc = new Process();
    //(Snip...) Setup the process
    proc.Start();
    proc.WaitForExit();

    //(Snip...) Do some housecleaning

    NativeMethods.ExitWindowsEx(0, 0);
}
Run Code Online (Sandbox Code Playgroud)

我真的很喜欢这个,因为任务栏中没有任何项目,并且alt-tab中没有任何内容显示.但是为了做到这一点,我放弃了对void WndProc(ref Message m) So等函数的访问权限.现在我无法收听Windows消息(喜欢WTS_REMOTE_DISCONNECT或者WTS_SESSION_LOGOFF)并且没有使用的句柄,因为bool WTSRegisterSessionNotification(IntPtr hWnd, int dwFlags);我希望我的代码更强大,所以它会做清理工作如果用户在关闭程序之前注销或断开会话.

关于我如何吃蛋糕和吃它的任何建议?

c# handle message-pump

11
推荐指数
3
解决办法
6703
查看次数

如何禁用所有.Net程序集的强名称验证?

如何通过config .net框架或IIS或项目的配置禁用系统中所有.Net程序集的.Net强名称验证?

http://nvea.host56.com/up/726daf2c9ee0.png (点击查看大图)

.net verification strongname config

11
推荐指数
4
解决办法
2万
查看次数

从加权列表中选择一个随机项

我正在尝试编写一个程序,从美国人口普查姓氏列表中选择一个随机名称.列表格式是

Name           Weight Cumulative line
-----          -----  -----      -
SMITH          1.006  1.006      1
JOHNSON        0.810  1.816      2
WILLIAMS       0.699  2.515      3
JONES          0.621  3.136      4
BROWN          0.621  3.757      5
DAVIS          0.480  4.237      6
Run Code Online (Sandbox Code Playgroud)

假设我将数据加载到类似的结构中

Class Name
{
    public string Name {get; set;}
    public decimal Weight {get; set;}
    public decimal Cumulative {get; set;}
}
Run Code Online (Sandbox Code Playgroud)

什么数据结构最适合保存名称列表,以及从列表中选择随机名称但名称分布与现实世界相同的最佳方法.

如果它在数据结构上有所不同,我将只处理前10,000行.

我已经尝试过关于加权随机性的其他一些问题但我在将理论转化为代码方面遇到了一些麻烦.我对数学理论知之甚少,所以我不知道这是一个"有或没有替代"的随机选择,我希望同一个名字能够不止一次出现,这就是那个意思.

c# random distribution weighted

10
推荐指数
1
解决办法
5991
查看次数

Signtool允许我签署代码,但Set-AuthenticodeSignature说"证书不适合代码签名"

我有一个自签名代码签名证书(使用此答案中的说明制作),当我使用时它可以正常工作signtool.exe.但是,如果我尝试使用Powershell进行签名,则会失败.

用signtool签名

C:\>signtool sign /v /n "VetWeb" SetupRDPPermissions.ps1
The following certificate was selected:
    Issued to: VetWeb
    Issued by: VetWeb CA
    Expires:   Sat Dec 31 18:59:59 2039
    SHA1 hash: 84136EBF8D2603C2CD6668C955F920C6C6482EE4

Done Adding Additional Store
Successfully signed: SetupRDPPermissions.ps1

Number of files successfully Signed: 1
Number of warnings: 0
Run Code Online (Sandbox Code Playgroud)

登录Powershell

PS C:\> $cert = @(Get-Childitem cert:\CurrentUser\My | Where-Object -FilterScript {$_.Subject -eq 'CN=VetWeb'})[0]
PS C:\> Set-AuthenticodeSignature SetupRDPPermissions.ps1 $cert
Set-AuthenticodeSignature : Cannot sign code. The specified certificate is not suitable for …
Run Code Online (Sandbox Code Playgroud)

powershell code-signing signtool

10
推荐指数
2
解决办法
1万
查看次数

IsKeyboardFocusable在Inspect Object中为true,但在我的应用程序中始终为false

我正在学习UI自动化,我发现我的"Inspect Object"克隆显示IsKeyboardFocusable即使是真的也总是假的,所有其他信息都是相同的(从图像中可以看出).有没有人知道为什么我在检索值时将此属性视为false?

在此输入图像描述

c# ui-automation winforms

10
推荐指数
1
解决办法
894
查看次数

Visual Studio 2017禁用依赖性验证

如何在Visual Studio 2017 RC中禁用依赖项验证?每当我打开C#解决方案时,它总是在解决方案资源管理器中向我显示一条消息:"需要更新一个或多个项目以执行依赖性验证",并带有"更新"按钮.当我第一次打开它时,它执行了一些自动更新的包和配置文件,我以后必须删除它们.

我需要在VS2017和VS2015之间共享解决方案,并且不想引入任何后向不兼容性.

c# visual-studio visual-studio-2017

10
推荐指数
1
解决办法
3497
查看次数