Process.Start("C:\Windows\system32\cmd.exe"

sp_eedo
Дата: 28.01.2010 13:06:56
Хочу выкинуть с сервера пару сессий?
пробую что-то типа этого:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim UserName = "Administrator"
        Dim UserPassString As String = "xxxxxxx"
        Dim UserPass = New Security.SecureString()
        SetPass(UserPass, UserPassString)

        Dim prc As Process = Process.Start("C:\Windows\system32\cmd.exe", UserName, UserPass, "xxxxx")
        Process.Start("C:\Windows\system32\tsdiscon.exe 1 /server:10.99.2.235 -v")
    End Sub

    Private Sub SetPass(ByRef UserPass As Security.SecureString, ByVal PassString As String)
        While PassString.Length > 0
            UserPass.AppendChar(PassString.Substring(0, 1))
            PassString = PassString.Substring(1, (PassString.Length - 1))
        End While
    End Sub
Неработает.
sp_eedo
Дата: 28.01.2010 13:49:23
sp_eedo,

Народ, подскажите , можно ли

после того как запустилась CMD под администратором,
выполнить комманду tsdisconn ?
vagner
Дата: 28.01.2010 14:46:44
sp_eedo,

судя по коду, Вы запускаете один процесс под админом, а затем ДРУГОЙ процесс под текущей учеткой. Запускайте tsd так же как и cmd, а cmd вообще не запускайте.
sp_eedo
Дата: 28.01.2010 14:49:16
vagner,

да вы правы, я пробовал
так
Process.Start("C:\Windows\system32\tsdiscon.exe 1 /server:10.99.2.235 -v", UserName, UserPass, "xxxxx")
но тут уже пишет что файл не найден
vagner
Дата: 28.01.2010 14:54:40
sp_eedo,

значит, этот вариант Start'a ожидает только имя запускаемого экзешника. Параметры можно задать и другим способом. Создайте сначала Process, установите все необходимые параметры, и только потом его запускайте.

Извините за C#, но вот, например:
			Process p = new Process ( );
			// Redirect the output stream of the child process.
			p.StartInfo.CreateNoWindow = true;
			p.StartInfo.StandardOutputEncoding = Encoding.GetEncoding ( 866 );
			p.StartInfo.UseShellExecute = false;
			p.StartInfo.RedirectStandardOutput = true;
			p.StartInfo.FileName = "route";
			p.StartInfo.Arguments = "print";
			p.Start ( );
sp_eedo
Дата: 28.01.2010 17:49:03
vagner,

вот в формочке почему то не работает. =(((((((((((
(на шаге
p.Start();

пишет неверный дескриптор.
подскажите в чём может быть дело?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;

namespace win_session_dropper
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            drop("", "");
        }

        private void drop(string serverIP, string sessionNum)
        {
            Process p = new Process();
            // Redirect the output stream of the child process.
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(866);
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.UserName = @"Administrator";
            System.Security.SecureString UserPass = new System.Security.SecureString();
            string PassString = @"xxxxxxxx";
            SetPass(UserPass, PassString);
            p.StartInfo.Password = UserPass;
            p.StartInfo.FileName = @"C:\Windows\system32\tsdiscon.exe";
            p.StartInfo.Arguments = @"1 /server:10.99.2.235 -v";
            p.Start();


        }

        public static void SetPass(System.Security.SecureString UserPass, string PassString)
        {
            while (PassString.Length > 0)
            {
                char s = Convert.ToChar(PassString.Substring(0, 1));
                UserPass.AppendChar(s);
                PassString = PassString.Substring(1, (PassString.Length - 1));

            }
        }

    }

}

хотя в ConsoleApplication все арботает
vagner
Дата: 28.01.2010 18:16:30
sp_eedo,

0. Закомментируйте p.StartInfo.RedirectStandardOutput = true;. Если отработает и вам не
нужно перехватывать вывод запускаемой проги, тогда так и оставьте. Если нет - шаг 1.
1. уберите drop из OnLoad
2. киньте на форму кнопку и в ее обработчике вызовите drop
3. если отработает, то я даже не знаю как перенсти этот код в OnLoad. Разве что попробовать BeginInvoke.
sp_eedo
Дата: 29.01.2010 11:23:17
vagner,

0. Закомментируйте p.StartInfo.RedirectStandardOutput = true

помогло.

спасибо вам большое.