小编use*_*033的帖子

无法加载ps1,因为在此系统上禁用了运行脚本

我尝试powershell从c#运行脚本.

首先,我设置ExecutionPolicyUnrestricted和脚本从现在正在运行PowerShell ISE.

现在这是我的代码:

class Program
{
    private static PowerShell ps;
    static void Main(string[] args)
    {
        ps = PowerShell.Create();
        string ps1File = Path.Combine(Environment.CurrentDirectory, "script.ps1");
        ExecuteScript(ps1File);
        Console.ReadLine();
    }

    static void ExecuteScript(string script)
    {
        try
        {
            ps.AddScript(script);
            Collection<PSObject> results = ps.Invoke();
            Console.WriteLine("Output:");
            foreach (var psObject in results)
            {
                Console.WriteLine(psObject);
            }
            Console.WriteLine("Non-terminating errors:");
            foreach (ErrorRecord err in ps.Streams.Error)
            {
                Console.WriteLine(err.ToString());
            }
        }
        catch (RuntimeException ex)
        {
            Console.WriteLine("Terminating error:");
            Console.WriteLine(ex.Message);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

输出是:

无法加载ps1,因为在此系统上禁用了运行脚本.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=135170上的 …

c# powershell

14
推荐指数
16
解决办法
2万
查看次数

如何右键单击列表框中的项目并在WPF上打开菜单

我有包含文件的列表框,我想能够右键单击并打开像删除这样的菜单,以便从列表框中删除文件.

目前我右键单击列表框中的项目后有此功能

private void listBoxFiles_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{

}
Run Code Online (Sandbox Code Playgroud)

然后我在右键单击后在XAML删除菜单中实现

          <ListBox.ContextMenu>
                <ContextMenu>                                                        
                    <MenuItem Header="Delete"/>
                </ContextMenu>
            </ListBox.ContextMenu>
Run Code Online (Sandbox Code Playgroud)

从我的ListBox中删除文件的功能:

private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
{            
    if (listBoxFiles.SelectedIndex == -1)
    {
        return;
    }

    //string filePath = (listBoxFiles.SelectedItem).ToString();
    int index = listBoxFiles.SelectedIndex;
    listBoxFiles.Items.RemoveAt(index);
}
Run Code Online (Sandbox Code Playgroud)

c# wpf

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

如何使用lambda表达式c#启动Thread

我有这门课:

public class Statistics
{
    List<string> _lsit;

    public List<string> ipList
    {
        get { return _lsit; }
        set { _lsit = value; }
    }

    string _Path = @"C:\Program Files\myApp.exe";
    string _Path = "";
    ProcessStartInfo ps = null;

    public getStatistics(string Path)
    {
        _Path = Path;
        getStatistics();
    }
}
Run Code Online (Sandbox Code Playgroud)

我想用不同的Thead启动函数Statistics,我做了类似的事情:

Statistics stat = new Statistics (some path);
Thread<List<string>> lList = new Thread<List<string>>(() => tsharkIps.getStatistics());
Run Code Online (Sandbox Code Playgroud)

但编译器错误说"非泛型类型'System.Threading.Thread'不能与类型参数一起使用"

我没有写完我所有的课程,只想知道热线开始

谢谢

c# multithreading

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

如何将微秒和纳秒添加到 DatetTime?

我想将微秒和纳秒添加到DateTime.

DateTime dateTime = DateTime.Now;

for(int i = 0; i < 100000; i++)
{
    dateTime  = dateTime.AddMilliseconds(0.1);
    Console.WriteLine(dateTime.ToString("yyyy.MM.dd,HH:mm:ss.ffffff"));          
}
Run Code Online (Sandbox Code Playgroud)

我看不出我的有什么不同dateTime。这是正确的方法吗?

c# datetime

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

C# 监听键盘组合

我想编写简单的代码program,在某些地方发送我的用户和密码,例如当我想登录网站时,我发现了这个项目正在听键盘。

所以我有这个功能:

private void HookManager_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{

}

private void HookManager_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{

}

private void HookManager_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{

}
Run Code Online (Sandbox Code Playgroud)

例如,当我按下 键时,a我会得到这样的结果:

int value = e.KeyValue; // 65
Keys key = e.KeyCode;   // A
Run Code Online (Sandbox Code Playgroud)

所以我想知道如何捕获特定的keyboard combination而不是仅一个key的例子Ctrl + l

c# keyboard-events winforms

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

如何打印功能的返回值

所以我有这个简单的function返回我当前的脚本位置:

function Get-CurrentDir
{
    $MyInvocation.MyCommand.Path
}
Run Code Online (Sandbox Code Playgroud)

我想打印这个,所以我在功能声明后尝试使用PowerShell ISE:

Write-Host $(Get-CurrentDir)
Write-Host (Get-CurrentDir)
Write-Host Get-CurrentDir
Run Code Online (Sandbox Code Playgroud)

这是我的输出:

Write-Host $(Get-CurrentDir) --> Write-Host $(Get-CurrentDir)
Write-Host (Get-CurrentDir) --> Write-Host (Get-CurrentDir)
Write-Host Get-CurrentDir --> Write-Host Get-CurrentDir
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

powershell

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

C语言如何从输入中获取字符串

这是我尝试过的:

printf("Please venter first string\n");
char str[127];
scanf_s("%s", &str);
Run Code Online (Sandbox Code Playgroud)

并得到了这个例外:

在 strcmp.exe 中的 0x0FD2C700 (ucrtbased.dll) 处引发异常:0xC0000005:访问冲突写入位置 0x00500000。

我也试试这个:

printf("Please venter first string\n");
char str[127];
scanf_s("%d", &str);
Run Code Online (Sandbox Code Playgroud)

在这种情况下也不例外,但我得到了又长又奇怪的字符串。

c input

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

WPF:边界下的标签 CornerRadius

所以这是我的习惯GroupBox

<Grid Width="550" Height="140" Margin="20,0,0,0">
    <Grid.RowDefinitions>
        <RowDefinition Height="20"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Border BorderThickness="1,1,1,0" BorderBrush="Gray" CornerRadius="5,5,0,0" >
        <Label
            Height="25"
            Width="60"
            HorizontalAlignment="Left"
            Background="#FF7AA0CD"
            BorderBrush="Gray"
            BorderThickness="1"
            Foreground="Gainsboro"
            Content=" Options"
            Margin="10,-18,0,0"/>
    </Border>
    <Border Grid.Row="1" BorderThickness="1,0,1,1" BorderBrush="Gray" CornerRadius="0,0,5,5">
        <StackPanel Orientation="Vertical" Margin="0,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left">
            <StackPanel Orientation="Horizontal" Margin="10,0,0,0" >
                <Label 
        Content="Interface: "
        Margin="0,3,0,0"/>
                <ComboBox
            MaxDropDownHeight="110"
            Style="{DynamicResource ComboBoxFlatStyle}"
            ItemsSource="{Binding interfaces}"
            Width="400"
            Height="28"
            SelectedIndex="1"
            FontSize="12"
            Margin="40,0,0,0"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="10,2,0,0">
                <Label 
            Content="Capture filter:"
            Margin="0,3,0,0"/>
                <TextBox
            Name="tbSnifferFilter"
            Width="399"
            Height="28"
            TextChanged="tbSnifferFilter_TextChanged"
            LostFocus="tbSnifferFilter_LostFocus"
            Margin="21,0,0,0">
                    <TextBox.ToolTip>
                        <TextBlock>
                The expression selects which …
Run Code Online (Sandbox Code Playgroud)

wpf styles groupbox

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

Eclipse上的选项在哪里定义"{"和"}"将在同一行并自动自动完成?

我希望那对括号('{'和'}')将是自动的:

public static void main(String[] args)
{   

}
Run Code Online (Sandbox Code Playgroud)

代替:

public static void main(String[] args){ 

}
Run Code Online (Sandbox Code Playgroud)

有没有办法像Visual Studio一样定义自动完成?

java eclipse

0
推荐指数
1
解决办法
56
查看次数

Powershell被'_'分割返回空

所以我有几个文件的文件夹:

$files = @(Get-ChildItem "myPath")
Run Code Online (Sandbox Code Playgroud)

我可以通过$files包含几个项目的调试器看到,我想拿第一个:

$files[0] = "123_this.is.string"
Run Code Online (Sandbox Code Playgroud)

我想分裂'_'并带走123

$splitted = $files[0] -split "_"
Run Code Online (Sandbox Code Playgroud)

所以在这里我可以看到它$splitted是空的。

任何建议为什么这种奇怪的行为?

powershell

0
推荐指数
1
解决办法
186
查看次数