获取安卓内置外置SD卡根目录

使用下面的代码,获取安卓内置或外置SD卡根目录:

//内置sd卡路径
String sdcardPath = System.getenv("EXTERNAL_STORAGE");
//内置sd卡路径
String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath();

//外置sd卡路径
String extSdcardPath = System.getenv("SECONDARY_STORAGE");

C#执行DOS命令,返回DOS命令的输出

使用下面的代码,可以实现C#执行DOS命令,并返回DOS命令的输出:

 /// <summary> 
/// 执行DOS命令,返回DOS命令的输出 
/// </summary> 
/// <param name="dosCommand">dos命令</param> 
/// <param name="milliseconds">等待命令执行的时间(单位:毫秒), 
/// 如果设定为0,则无限等待</param> 
/// <returns>返回DOS命令的输出</returns> 
public static string Execute(string command, int seconds)
{
	string output = ""; //输出字符串 
	if (command != null && !command.Equals(""))
	{
		Process process = new Process();//创建进程对象 
		ProcessStartInfo startInfo = new ProcessStartInfo();
		startInfo.FileName = "cmd.exe";//设定需要执行的命令 
		startInfo.Arguments = "/C " + command;//“/C”表示执行完命令后马上退出 
		startInfo.UseShellExecute = false;//不使用系统外壳程序启动
		startInfo.RedirectStandardInput = false;//不重定向输入 
		startInfo.RedirectStandardOutput = true; //重定向输出 
		startInfo.CreateNoWindow = true;//不创建窗口 
		process.StartInfo = startInfo;
		try
		{
			if (process.Start())//开始进程 
			{
				if (seconds == 0)
				{
					process.WaitForExit();//这里无限等待进程结束 
				}
				else
				{
					process.WaitForExit(seconds); //等待进程结束,等待时间为指定的毫秒 
				}
				output = process.StandardOutput.ReadToEnd();//读取进程的输出 
			}
		}
		catch (Exception ex)
		{
			Console.WriteLine(ex.Message);//捕获异常,输出异常信息
		}
		finally
		{
			if (process != null)
				process.Close();
		}
	}
	return output;
}

web.config中配置数据库连接 

asp.net的开发中,数据库连接信息一般都在是web.config中配置的,配置方法如下:

<connectionStrings>
    <add name="conn" connectionString="Data Source=123.206.101.218;Initial Catalog=MyShop;Persist Security Info=True;User ID=sa;Password=123456" providerName="System.Data.SqlClient" />
</connectionStrings>

调用方法:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Web;
namespace MyShop
{
    class Db
    {
        public static SqlConnection GetConnection()
        {
            var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
            var conn = new SqlConnection(connectionString);
            return conn;
        }
    }
}

ASP.NET 使用FastMember 把List转成 DataTable

FastMember 可以在 Nuget 里找到

配合 Dapper 很好用。

用 Dapper 的时候,要定义实体,像这样调用conn.Query<OrderModel>(sql).ToList(), 不然 FastMember 转成的 DataTable 是空的

private void btnSearch_Click(object sender, EventArgs e)
{
	using (var conn = Db.OpenConnection())
	{
		var sql = "SELECT * FROM dbo.[Order] where 客户名称 like '%张%'";
		var data = conn.Query<OrderModel>(sql).ToList();

		DataTable table = new DataTable();
		using (var reader = ObjectReader.Create(data))
		{
			table.Load(reader);
			this.dataGridView1.DataSource = table;
		}
		
	}
}

VC获取进程加载的DLL模块

VC++获取进程加载的DLL模块:

#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <psapi.h>

// To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS// and compile with -DPSAPI_VERSION=1

int PrintModules(DWORD processID)
{
    HMODULE hMods[1024];
    HANDLE hProcess;
    DWORD cbNeeded;
    unsigned int i;

    // Print the process identifier.

    printf("\nProcess ID: %u\n", processID);

    // Get a handle to the process.

    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
                               PROCESS_VM_READ,
                           FALSE, processID);
    if (NULL == hProcess)
        return 1;

    // Get a list of all the modules in this process.

    if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
    {
        for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)
        {
            TCHAR szModName[MAX_PATH];

            // Get the full path to the module's file.

            if (GetModuleFileNameEx(hProcess, hMods[i], szModName,
                                    sizeof(szModName) / sizeof(TCHAR)))
            {
                // Print the module name and handle value.

                _tprintf(TEXT("\t%s (0x%08X)\n"), szModName, hMods[i]);
            }
        }
    }

    // Release the handle to the process.

    CloseHandle(hProcess);

    return 0;
}

int main(void)
{

    DWORD aProcesses[1024];
    DWORD cbNeeded;
    DWORD cProcesses;
    unsigned int i;

    // Get the list of process identifiers.

    if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
        return 1;

    // Calculate how many process identifiers were returned.

    cProcesses = cbNeeded / sizeof(DWORD);

    // Print the names of the modules for each process.

    for (i = 0; i < cProcesses; i++)
    {
        PrintModules(aProcesses[i]);
    }

    return 0;
}