作者ljhgc (是嚮往亦或逃避)
看板C_Sharp
標題[問題] 遠端安裝
時間Wed Aug 11 19:48:11 2010
小弟現在用IIS架設一個web
其中有一個頁面是可以選擇要下載哪些東西(server會列出來)
(要進入此頁面時,會跳出windows驗證,必需輸入可用在登錄server的windows帳密)
下載後是存放在server的某個資料夾底下(不在web底下)
下載完可以選擇要安裝哪個
現在卡在,當執行安裝檔時,總是會用ASPNET的身分去跑
這樣就變得沒有權限可以作安裝的動作了
以下是我的code
=========================
public static WindowsIdentity gwinId;
public static WindowsImpersonationContext cix;
protected void Page_Load(object sender, EventArgs e)
{
gwinId = (WindowsIdentity)HttpContext.Current.User.Identity;
try
{
cix = gwinId.Impersonate();
}
catch
{
//Impersonate() fail
}
}
void btn_Install_Click(object sender, EventArgs e)
{
string argIn = "/k cd \"" + fileFolderPath + "\"";
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = argIn;
p.Start();
p.StandardInput.WriteLine("filename");
p.StandardInput.WriteLine("exit");
p.WaitForExit();
p.Close();
}
====================================================================
小弟我其實對C#不熟,應該說是根本沒接觸過
是這幾天某些因素,不得不用C#
請問有大大能替我解惑嗎?
為什麼在執行cmd.exe或安裝檔時,總是會用ASPNET去執行
而不是使用一開始頁面load時驗證過的帳戶呢?
謝謝!!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.120.37.166
※ 編輯: ljhgc 來自: 59.120.37.166 (08/16 13:22)
→ ljhgc:謝謝S大的回應,不過連結裡的方法都不是我要的 08/16 13:22
→ ljhgc:方法一,需要在Web.config裡寫入帳密,這在安全上有隱憂 08/16 13:22
→ ljhgc:方法二,我並不知道user會以哪個帳密登入,且我也不知道 08/16 13:22
→ ljhgc:server端的帳密 08/16 13:22
→ ljhgc:我這網頁在user要開啟時,便會先跳出window驗證了, 08/16 13:22
→ ljhgc:驗證過了網頁才會開啟,我的code我有在中間去監看, 08/16 13:22
→ ljhgc:確實有模擬並取得user輸入的window account, 08/16 13:22
→ ljhgc:可是不曉得為什麼我要去run別隻程式時,卻會以ASP.NET執行 08/16 13:23