• Home
  • Linux
  • Docker
  • Windows
    • PS
    • C#
    • Exchange Server
  • Other
    • Perl
    • IPV6
    • MacOS
  • DB
    • MSSQL
    • MariaDB
    • PG

Home

Читаем XLSL на C#

Details
Written by: Senka
Category: C#
Created: 11 June 2013
Hits: 1346

private DataTable openXLSX(string filename)

{

    OleDbConnection connection = null;

    OleDbCommand command = null;

    OleDbDataAdapter adapter = null;

    DataSet dataset = new DataSet();

    try

    {

        connection = new OleDbConnection(string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", filename));

        connection.Open();

 

        DataTable sheetsName = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });

 

        string firstSheetName = sheetsName.Rows[0][2].ToString();

 

        command = new OleDbCommand(string.Format("SELECT * FROM [{0}]",firstSheetName),  connection);

        //command.CommandType = CommandType.Text;

        adapter = new OleDbDataAdapter(command);

        adapter.Fill(dataset);

    }

    catch (Exception exception)

    {

        MessageBox.Show(exception.ToString());

    }

    finally

    {

        if (connection.State == ConnectionState.Open)

            connection.Close();

        connection.Dispose();

        command.Dispose();

        adapter.Dispose();

    }

    return dataset.Tables[0];

}

 

//dataGridView1.DataSource = dt;

//dataGridView1.Update();

POST запрос на C#

Details
Written by: Senka
Category: C#
Created: 11 June 2013
Hits: 1364

private static string POST(string Url, string Data)

{

    System.Net.WebRequest req = System.Net.WebRequest.Create(Url);

    req.Method = "POST";

    req.Timeout = 60000;

    req.ContentType = "application/x-www-form-urlencoded";

 

    UTF8Encoding utf8 = new UTF8Encoding();

    byte[] sentData = utf8.GetBytes(Data);

    //byte[] sentData = Encoding.GetEncoding(1251).GetBytes(Data);

    //sentData = Encoding.Convert(1251, "utf-8", sentData);

 

    req.ContentLength = sentData.Length;

    System.IO.Stream sendStream = req.GetRequestStream();

    sendStream.Write(sentData, 0, sentData.Length);

    sendStream.Close();

    System.Net.WebResponse res = req.GetResponse();

    System.IO.Stream ReceiveStream = res.GetResponseStream();

    System.IO.StreamReader sr = new System.IO.StreamReader(ReceiveStream, Encoding.UTF8);

    //Кодировка указывается в зависимости от кодировки ответа сервера

    Char[] read = new Char[256];

    int count = sr.Read(read, 0, 256);

    string Out = String.Empty;

    while (count > 0)

    {

        String str = new String(read, 0, count);

        Out += str;

        count = sr.Read(read, 0, 256);

    }

    return Out;

}

Пароль никогда не устаревает

Details
Written by: Senka
Category: Power Shell
Created: 11 June 2013
Hits: 1242

Get-ADUser -Filter * -property * | Select SamAccountName,Name,CanonicalName,EmailAddress,PasswordLastSet, WhenCreated,PasswordExpired,PasswordNeverExpires,ProfilePath,Department, Title,Manager,@{Name="Disabled"; Exp={$_.useraccountcontrol -band 2}}|?{$_.Disabled -eq 0 -and $_.PasswordNeverExpires -eq 'True'}| export-csv user_password_never_expire.csv -encoding Default

Инвентаризация серверов

Details
Written by: Senka
Category: Power Shell
Created: 11 June 2013
Hits: 1379

$computers = Get-ADComputer -filter {OperatingSystem -like '*server*'} -Properties * | Select Name,OperatingSystem,OperatingSystemVersion,OperatingSystemServicePack, PrimaryGroup,IPv4Address,IPv6Address,CanonicalName,WhenCreated, LastlogonTimestamp,PasswordLastSet,@{Name="Disabled"; Exp={$_.useraccountcontrol -band 2}}| ?{$_.Disabled -eq 0}

Read more …

Активные пользователи в AD

Details
Written by: Senka
Category: Power Shell
Created: 11 June 2013
Hits: 1215

$date = (Get-Date).AddDays(-90)

Get-ADUser -Filter {lastlogontimestamp -gt $date} -property * | Select SamAccountName,Name, EmailAddress,CanonicalName,Manager,lastlogontimestamp,@{Name="Disabled"; Exp={$_.useraccountcontrol -band 2}}| ?{$_.Disabled -eq 0} | export-csv active_users.csv -Delimiter ";" -NoTypeInformation -Encoding Default

 

  1. Активность POP/SMTP почтовых ящиков
  2. Список пользователей в группе
  3. Инвентаризация ПО в компании
  4. Тестируем скорость открытия файлов из шары

Subcategories

Power Shell Article Count:  53

C# Article Count:  10

Perl Article Count:  1

Exchange Server Article Count:  15

Other Article Count:  24

MSSQL Article Count:  17

Windows Article Count:  25

MariaDB Article Count:  3

Linux Article Count:  8

Docker Article Count:  2

pg Article Count:  2

Page 30 of 32

  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

Login Form

  • Forgot your password?
  • Forgot your username?

Statistics

  • Users 2
  • Articles 176
  • Articles View Hits 158046