默默的运行命令行程序用C#在WINCE [英] Run command line program silently with c# on wince

查看:399
本文介绍了默默的运行命令行程序用C#在WINCE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我再次需要一些帮助。

我在使用.NET Compact Framework和C#编程语言来开发运行的WinCE 5.0的移动设备。

I'm using the .net Compact Framework and the programming language C# to develop for mobile devices that are running WinCE 5.0.

我要完成的任务是通过编程方式安装网络驱动器。要做到这一点,应用程序运行以下code在后台线程:

What I want to accomplish is to programmatically mount a network drive. To do so, the app runs the following code in a background thread:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "net";
startInfo.UseShellExecute = false;
startInfo.Arguments = @"use logs \\server\logs /user:dom\uname /password:pw";
Process p = Process.Start(startInfo);
p.WaitForExit(5000);

现在我的问题是,这个code将在前台显示一个控制台和写入命令并从命令以及答案。此外,控制台不会消失了。

Now my problem is, that this code will display a console in the foreground and writes the command to it and the answer from the command as well. Also, the console won't disappear anymore.

参数UseShellExecute'似乎并没有显示出任何效果。

The parameter 'UseShellExecute' doesn't seem to show any effect.

我读过有关参数CreateNoWindow,但它并没有在紧凑的框架存在。

I've read about the parameter 'CreateNoWindow', but it doesn't exist in the compact framework.

所以朋友们,有没有可能在后台运行的净命令,用户应该不会注意到并肯定不会看到包括明文密码的命令。

So folks, is there a possibility to run net-commands in the background, the user shouldn't notice and certainly not see the command including the password in plain text.

我希望你的想法。

在提前
非常感谢 托比

Many thanks in advance
Toby

推荐答案

您可以使用的 WNetAddConnetion3 通过P /调用它(这里是的声明) 。这里是声明的NETRESOURCE结构:

You can use WNetAddConnetion3 by P/Invoking it (here is the declaration).Here is the declaration for the NetResource struct:

    [StructLayout(LayoutKind.Sequential)]
    internal struct NetResource
    {
        public uint dwScope;
        public uint dwType;
        public uint dwDisplayType;
        public uint dwUsage;
        [MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)]
        public string lpLocalName;
        [MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)]
        public string lpRemoteName;
        [MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)]
        public string lpComment;
        [MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)]
        public string lpProvider;
    }

这篇关于默默的运行命令行程序用C#在WINCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆