小编Bou*_*es6的帖子

如何以编程方式创建系统还原点?

我正在寻找一种通过按下按钮创建具有当前日期和时间的系统还原点的方法.我试过在网上搜索一个简单的方法,但我还没找到.

我发现这个代码片段来自:http://msdn.microsoft.com/en-us/library/windows/desktop/aa378847%28v=vs.85%29.aspx但它是在VB而不是C#,我试过转换它有点但我不认为我在翻译它做得很好.

'CreateRestorePoint Method of the SystemRestore Class
'Creates a restore point. Specifies the beginning and 
'the ending of a set of changes so that System Restore 
'can create a restore point.This method is the 
'scriptable equivalent of the SRSetRestorePoint function.

Set Args = wscript.Arguments
If Args.Count() > 0 Then
    RpName = Args.item(0)
Else 
    RpName = "Vbscript"
End If

Set obj = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:SystemRestore")

If (obj.CreateRestorePoint(RpName, 0, 100)) = 0 Then
wscript.Echo "Success"
Else 
    wscript.Echo "Failed"
End …
Run Code Online (Sandbox Code Playgroud)

c# windows backup restore-points

6
推荐指数
2
解决办法
6256
查看次数

使用用户输入在Active Directory中搜索计算机名称

您好,我试图在我的Windows窗体程序中添加一个函数,该函数允许用户在文本框中键入他们想要在Active Directory中搜索的计算机或计算机.用户将在文本框中输入搜索字符串,然后点击按钮,与该搜索结果匹配的计算机将显示在单独的搜索框中.到目前为止,这是我的代码.

我还希望每个计算机名称都在一个单独的行上,例如:

computername1            
computername2        
computername3
Run Code Online (Sandbox Code Playgroud)

谢谢!

这是按钮内部的样子:

List<string> hosts = new List<string>();
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://servername";

try
{
    string adser = txtAd.Text; //textbox user inputs computer to search for

    DirectorySearcher ser = new DirectorySearcher(de);
    ser.Filter = "(&(ObjectCategory=computer)(cn=" + adser + "))"; 
    ser.PropertiesToLoad.Add("name");

    SearchResultCollection results = ser.FindAll();

    foreach (SearchResult res in results) 
    //"CN=SGSVG007DC" 
    {
       string computername = res.GetDirectoryEntry().Properties["Name"].Value.ToString();
       hosts.Add(computername);
       //string[] temp = res.Path.Split(','); //temp[0] would contain the computer name ex: cn=computerName,..
       //string adcomp = (temp[0].Substring(10));
       //txtcomputers.Text …
Run Code Online (Sandbox Code Playgroud)

c# active-directory

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

c#使用嵌入资源中的excel文件

我正在为我的女朋友编写一个评分程序,但我一直在尝试将数据输出到我嵌入到程序中的 excel 文件中。我目前正在写入一个空白的 excel 文件,但想使用预制的 excel 文件并将数据导出到适当的单元格。我不知道如何告诉程序使用资源文件夹中的 xls 文件,而不是制作一个空白的 excel 文件。这是到目前为止保存它的代码。我正在使用 C# 2008 快速版。

谢谢

我的资源参考是:Properties.Resources.gradesheet

Excel.Application xlApp;
        Excel.Workbook xlWorkBook;            
        Excel.Worksheet xlWorkSheet;

        object misValue = System.Reflection.Missing.Value;


        xlApp = new Excel.ApplicationClass();
        xlWorkBook = xlApp.Workbooks.Add(misValue);

        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
        //add data to excel
        xlWorkSheet.Cells[1, 1] = firstName;
        xlWorkSheet.Cells[2, 1] = lastName;




        xlWorkBook.Close(true, misValue, misValue);
        xlApp.Quit();

        releaseObject(xlWorkSheet);
        releaseObject(xlWorkBook);
        releaseObject(xlApp);
Run Code Online (Sandbox Code Playgroud)

c#

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

后台工作人员更新列表视图中的多个项目

我正在尝试使用此方法更新列表框中的多个值:此方法的作用是复制指定目录的内容,但它将当前文件名输出到后台工作进程进度更改事件。

private bool CopyDirectory(string SourcePath, string DestinationPath, bool Recursive, BackgroundWorker worker, DoWorkEventArgs e)
    {
        List<string> Paths = new List<string>();
        List<string> Files = new List<string>();

        //for windows xp My documents
        if(!Directory.Exists(SourcePath))
        {
            SourcePath = SourcePath.Replace(@"C$\Users\", @"C$\Documents and Settings");

            int doccount = Regex.Matches(SourcePath, "Documents").Count;

            //if source contains 2 documents
            if(doccount > 1)
            {
                ReplaceLastOccurrence(SourcePath, "Documents", "My Documents");
            }
        }


        //set file permissions
        FileIOPermission f2 = new FileIOPermission(FileIOPermissionAccess.Read, SourcePath);
        f2.AllLocalFiles = FileIOPermissionAccess.Read;

        f2.Demand();

        foreach (string StringPath in DirectoryList(SourcePath, Recursive, null))
            Paths.Add(StringPath);
        foreach (string …
Run Code Online (Sandbox Code Playgroud)

c# listview backgroundworker

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