我正在使用与PowerShell的schtask命令.发生的问题是当它是C:\ Program Files \时它认为路径只是C:\ Program而路径的其余部分是争论.我试图通过使用""字段的前置和后置来逃避它但确实有所不同.我怎么能完成这个?我不能对路径进行硬编码,因为它可以在用户安装时更改.
我在Windows 7 x64中创建了这个.它创建脚本返回的任务.但是,当我在任务计划中查看它时,任务的属性,然后是操作,并点击编辑.它将程序显示为C:\ Program,然后将其余部分显示为参数.

脚本:
$folder = Split-Path $MyInvocation.MyCommand.Path -Parent
$app = "\Demon.DatabasePurge.exe"
$exe = $app.Insert(0, $folder)
schtasks /create /tn "Demon Purge Job" /sc daily /st 00:00:00 /tr $exe
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
$folder = Split-Path $MyInvocation.MyCommand.Path -Parent
$app = "\Demon.DatabasePurge.exe`""
$exe = $app.Insert(0, $folder)
$exe2 = $exe.Insert(0, "`"")
schtasks /create /tn "Demon Purge Job" /sc daily /st 00:00:00 /tr $exe2
Run Code Online (Sandbox Code Playgroud) 我目前有一个具有名为Id的公共属性的对象.当我存储对象时,我希望Id成为数据的一部分,而不是像目前那样成为文档ID.创建文档存储时,我只设置连接字符串.
using (var session = documentStore.OpenSession())
{
session.Store(a);
session.SaveChanges();
}
a can be thought of an object as:
public class A
{
public Guid Id { get; set; }
//other properties
}
Run Code Online (Sandbox Code Playgroud)
所以要么我希望它生成一个随机Id,要么让数据和documentId都是A类的Id属性.
编辑:
所以有两种可能:1.文件ID = Id和
Data Section contains:
{
data //sorry if the notation is not correct, doing it off of memory
{
Id: [my guid]
//other properities
}
}
Run Code Online (Sandbox Code Playgroud)
或者包含Id和Document ID的数据=由raven随机生成
我有一个用C#.net编写的小.exe文件,我希望每24小时在服务器上运行一次。因此,我自然会只使用Windows Task Schedular而不是自己做数学。我已经创建了程序,但是我想创建一个安装程序,它可以完成所有的设置。有没有办法像Visual Studio设置项目那样呢?如果没有的话,可以在安装后运行Powershell /批处理脚本吗?
底线:自动创建任务。
当前我可以使用DriveInfo.GetDrives()在c#中获取所有驱动器及其标签.然后我可以通过这种方法获得分区的磁盘索引/索引.
var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskPartition");
foreach (var queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_DiskPartition instance");
Console.WriteLine("Name:{0}", (string)queryObj["Name"]);
Console.WriteLine("Index:{0}", (uint)queryObj["Index"]);
Console.WriteLine("DiskIndex:{0}", (uint)queryObj["DiskIndex"]);
Console.WriteLine("BootPartition:{0}", (bool)queryObj["BootPartition"]);
}
Run Code Online (Sandbox Code Playgroud)
这个问题是DiskIndex,Name和Index基本上只是数字,而不是卷标,即C:\,D:\等......
那么底线如何将DriveInfo上的名称属性卷标作为DiskIndex?要么使用这种方法,要么使用更好的方法.
(这是以下内容:告诉驱动器是分区还是单独的硬盘)
编辑: 我找到Win32_LogicalDisk的管理查询,然后找到Win32_LogicalDiskToPartition.LogicalDisk具有卷,LogicalDisktoParition提供映射.但是,我似乎无法弄清楚如何获取地图.我试着寻找一个JOIN并选择值,但是如果没有在c#代码中进行大量循环,就无法找到关于如何连接的任何内容.