青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

S.l.e!ep.¢%

像打了激速一樣,以四倍的速度運(yùn)轉(zhuǎn),開心的工作
簡單、開放、平等的公司文化;尊重個(gè)性、自由與個(gè)人價(jià)值;
posts - 1098, comments - 335, trackbacks - 0, articles - 1
  C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

Lock Windows Desktop

Posted on 2009-10-24 20:48 S.l.e!ep.¢% 閱讀(737) 評論(0)  編輯 收藏 引用 所屬分類: VC
124 votes for this article.
Popularity: 10.03 Rating: 4.79 out of 5

1

2
2 votes, 1.6%
3
17 votes, 13.7%
4
105 votes, 84.7%
5
Is your email address OK? You are signed up for our newsletters but your email address is either unconfirmed, or has not been reconfirmed in a long time. Please click here to have a confirmation email sent so we can confirm your email address and start sending you newsletters again.

Note

In response to the many requests from VB (and other languages) coders, I finally took some time to update the project and move all the functions into a DLL so that any program developed in a language capable of calling Windows standard libraries (DLLs) can use them. To demonstrate these functions, I also included C and a VB projects.

Introduction

I manage a system where I need to restrict users from accessing the desktop and running other applications. The search for ways to achieve this returned several different techniques. Although in the end I didn't use any of the techniques described here, I decided to compile all the code in one application for everyone who should need it.

Note: I don't claim to be the author of any of the code presented in this article. The application is a compilation of several sources and I will try to acknowledge the authors whenever possible.

I. Hiding Desktop Windows

Hiding the Windows Desktop, Taskbar, Start Button,..., is generally achieved by passing the window handle returned by FindWindow() to ShowWindow().

If, for example, you want to hide the Taskbar, you can use the following code:

Collapse Copy Code
ShowWindow(FindWindow("Shell_TrayWnd", NULL), SW_HIDE);

If you want to hide the Start Button, you have to know the button control ID first and use the same technique:

Collapse Copy Code
ShowWindow(GetDlgItem(FindWindow("Shell_TrayWnd", NULL), 
  0x130), SW_HIDE);

How do I know that the Taskbar class name is "Shell_TrayWnd" or that the Start Button id is 0x130? I used the Spy++ utility that comes with Microsoft Visual C++ 6.0. You can use this technique for any window or control you wish to hide.

If you want just to disable the window, and not hide it, change the ShowWindow() call to EnableWindow().

You will see that if you hide the Desktop and the Taskbar, the Start Menu still pops up when you press the Win key or double click the desktop area. To find out how to prevent this unwanted behavior, you have to read the next section.

II. Disabling System Keys

I call system keys all the special key combinations that the operating system (OS) use to switch between tasks or bring up the Task Manager.

There are several ways to disable these key combinations.

Win9x/ME

You can disable all these key combinations (including Ctrl+Alt+Del) by fooling the operating system into thinking the screen saver is running. This can be accomplished with the following code:

Collapse Copy Code
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &bOldState, 0);

This trick doesn't work in Windows NT or higher (Win NT+), so you need other techniques.

Hooks

In Win NT+, one way to trap key switching combinations is to write a keyboard hook. You install a keyboard hook by calling SetWindowsHookEx():

Collapse Copy Code
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hInstance, 0);

The KeyboardProc() function is a callback function that is called by the OS every time a key is pressed. Inside KeyboardProc(), you decide if you want to trap the key or let the OS (or the next application in the hook chain) process it:

Collapse Copy Code
  LRESULT KeyboardProc(...)
  {
     if (Key == VK_SOMEKEY)
    return1;             // Trap key
return CallNextHookEx(...); // Let the OS handle it
  }

To release the hook, you use:

Collapse Copy Code
  UnhookWindowsHookEx(hKeyboardHook);

There are two type of hooks: local and global (or system wide) hooks. Local hooks can only trap events for your application, while global hooks can trap events for all the running applications.

To trap the switching task keys, it's necessary to write a global hook.

The Microsoft documentation states that global hook procedures should be placed in a separate DLL. The DLL is then mapped into the context of every process and can trap the events for each process -- that's why hooks are used to inject code into a remote process.

In my application, I wanted to avoid the use of an external library, so I set the global hook inside my own application (without an external library). This is accomplished by passing in the 3rd parameter of the SetWindowsHookEx() call, the instance handle of the application (and not the library as the documentation states). This technique works perfectly for Win 9x but Win NT+ is different. The same effect can be achieved by using the new keyboard and mouse low level hooks. These new hooks don't need an external library because they work differently from the other hooks. The documentation states "[...] the WH_KEYBOARD_LL hook is not injected into another process. Instead, the context switches back to the process that installed the hook and it is called in its original context. Then the context switches back to the application that generated the event.".

I'm not going into more details about hooks because there are many excellent articles dealing with this subject.

There's still one remaining problem: keyboard hooks cannot trap Ctrl+Alt+Del sequence! Why? Because the OS never sends this key combination to the keyboard hook chain. It is handled at a different level in the OS and is never sent to applications. So, how can we trap the Ctrl+Alt+Del key combination? Read the next section to find out.

Ctrl+Alt+Del

There are several ways to disable this key combination:

  1. Disable Task Manager. This doesn't trap the key combination, it simply disables the application (Task Manager) that pops up when this key combination is pressed. See below how to do this.
  2. Trap the keys using a keyboard device driver. For this, you need the DDK installed. I will not describe this method here.
  3. Write a GINA stub. GINA is the DLL that Winlogon uses to perform user authentication. I'm not going to discuss this method here, but you can find out how to do it here [16].
  4. Subclass the SAS window of the Winlogon process. For this, you must inject code into the Winlogon process and then subclass its Window Procedure. Two techniques for doing this are described later.

Disable Task Manager

To disable the Task Manager, you only have to enable the policy "Remove Task Manager", either using the Group Policy editor (gpedit.msc) or setting the registry entry. Inside my application, I used the registry functions to set the value for the following key:

Collapse Copy Code
HKCU\Software\Microsoft\Windows\CurrentVersion\
  Policies\System\DisableTaskMgr:DWORD

Set it to 1 to disable Task Manager and 0 (or delete key) to enable it again.

Subclassing Winlogon's SAS window

You subclass a window's procedure by calling:

Collapse Copy Code
SetWindowLong(hWnd, GWL_WNDPROC, NewWindowProc);

The call only works for windows created by your application, i.e., you cannot subclass windows belonging to other processes (the address of NewWindowProc() is only valid for the process that called the SetWindowLong() function).

So, how can we subclass Winlogon SAS window?

The answer is: you have to somehow map the address of NewWindowProc() into the address space of the remote process and pass it to the SetWindowLong() call.

The technique of mapping memory into the address space of a remote process is called Injection.

Injection can be accomplished in the following ways:

  1. Registry. To inject a DLL into a process, simply add the DLL name to the registry key.
    Collapse Copy Code
    HKLM\Software\Microsoft\Windows NT\
      CurrentVersion\Windows\AppInit_DLLs:STRING

    This method is only supported on Windows NT or higher.

  2. Injecting a DLL using hooks. This method is supported by all Windows versions.
  3. Injecting a DLL using CreateRemoteThread()/LoadLibrary(). Only usable in Windows NT or higher.
  4. Copy the code directly to the remote process using WriteProcessMemory() and start its execution by calling CreateRemoteThread(). Only usable in Windows NT or higher.

My preferred injection technique is the last one. It has the advantage of not needing an external DLL. To properly work this method requires very careful coding of the functions you are injecting onto the remote process. To help you to avoid common pitfalls of this technique, I inserted some tips at the beginning of the source code. For people who think this method is too dangerous, I included also the CreateRemoteThread()/LoadLibrary() method. Just #define DLL_INJECT and the application will use this method instead.

After injecting the code into Winlogon's subclassing, the SAS window reduces too:

  1. Getting the SAS window handle:
    Collapse Copy Code
    hSASWnd = FindWindow("SAS Window class", "SAS window");
  2. Subclass the SAS window procedure:
    Collapse Copy Code
    SetWindowLong(hSASWnd, GWL_WNDPROC, NewSASWindowProc);
  3. Inside NewSASWindowProc(), trap the WM_HOTKEY message and return 1 for the Ctrl+Alt+Del key combination:
    Collapse Copy Code
    LRESULT CALLBACK NewSASWindowProc(HWND hWnd, UINT uMsg,
      WPARAM wParam, LPARAM lParam)
    {
      if (uMsg == WM_HOTKEY)
      {
         // Ctrl+Alt+Del
    if (lparam == MAKELONG(MOD_CONTROL | MOD_ALT, VK_DELETE))
      return1;
      }
      return CallWindowProc(OldSASWindowProc, hWnd, wParam, lParam);
    }

Other Techniques

1. RegisterHotKey()/Me

I only managed to disable Alt+Tab and Alt+Esc key combinations using this method.

2. SystemParametersInfo(SPI_SETSWITCHTASKDISABLE/SPI_SETFASTTASKSWITCH)

In all the versions I tried, this method never worked!

3. Switch to a new desktop

With this technique, you create a new desktop and switch to it. Because the other processes (normally) run on the "Default" desktop (Winlogon runs on the "Winlogon" desktop and the screen saver runs on the "Screen-saver" desktop), this has the effect on effectively locking the Windows desktop until the process that runs in the new desktop has finished.

The following code describes the steps necessary to create and switch to a new desktop and run a thread/process in it:

Collapse Copy Code
						//
						 Save original desktop
  hOriginalThread = GetThreadDesktop(GetCurrentThreadId());
  hOriginalInput = OpenInputDesktop(0, FALSE, DESKTOP_SWITCHDESKTOP);

  // Create a new Desktop and switch to it
  hNewDesktop = CreateDesktop("NewDesktopName", NULL, NULL, 0, GENERIC_ALL, NULL);
  SetThreadDesktop(hNewDesktop);
  SwitchDesktop(hNewDesktop);

  // Execute thread/process in the new desktop
  StartThread();
  StartProcess();

  // Restore original desktop
  SwitchDesktop(hOriginalInput);
  SetThreadDesktop(hOriginalThread);

  // Close the Desktop
  CloseDesktop(hNewDesktop);

To assign a desktop to a thread, SetThreadDesktop(hNewDesktop) must be called from within the running thread. To run a process in the new desktop, the lpDesktop member of the STARTUPINFO structure passed to CreateProcess() must be set to the name of the desktop.

References

  1. Disabling Keys in Windows XP with Trapkeys by Paul DiLascia.
  2. Trapping CtrlAltDel; Hide Application in Task List on Windows 2000/XP by Jiang Sheng.
  3. Three ways to inject your code into another process by Robert Kuster.
  4. Hooks and DLLs by Joseph M. Newcomer.
  5. Keyboard Hooks by H. Joseph.
  6. An All-Purpose Keyboard Hooker by =[ Abin ]=.
  7. Hooking the Keyboard by Anoop Thomas.
  8. HOOK - A HowTo for setting system wide hooks by Volker Bartheld.
  9. Systemwide Windows Hooks without external DLL by RattleSnake.
  10. Cross Process Subclassing by Venkat Mani.
  11. How to subclass Unicode Windows from ANSI Application by Mumtaz Zaheer.
  12. Disabling the Alt-Tab key combination by Dan Crea.
  13. Hiding/Showing the Windows Taskbar by Ashutosh R. Bhatikar.
  14. Protecting Windows NT Machines by Vishal Khapre.
  15. Disabling the Windows Start Button by Aaron Young.
  16. Using GINA.DLL to Spy on Windows User Name & Password And to Disable SAS (Ctrl+Alt+Del) by Fad B.
  17. Adding Your Logo to Winlogon's Dialog by Chat Pokpirom.

Final Notes

In the introduction, I referred that at the end I didn't use none of the techniques described in this article. The strongest method of securing the Windows desktop is to change the system shell by your own shell (that is, by your own application). In Windows 9x, edit the file c:\windows\system.ini, and in the [boot] section, change the key shell=Explorer.exe by shell=MyShell.exe.

In Windows NT or higher, you can replace the shell by editing the following Registry key:

Collapse Copy Code
HKLM\Software\Microsoft\Windows NT\
  CurrentVersion\Winlogon\Shell:STRING=Explorer.Exe

This is a global change and affects all users. To affect only certain users, edit the following Registry key:

Collapse Copy Code
HKLM\Software\Microsoft\WindowsNT\CurrentVersion\
  Winlogon\Userinit:STRING=UserInit.Exe

Change the value of Userinit.exe by MyUserInit.exe.

Here's the code for MyUserInit:

Collapse Copy Code
						#include
						
								<
								windows.h
								>
						
						#include
						
								<
								Lmcons.h
								>
						
						#define  BACKDOORUSER     TEXT("smith")
#define  DEFAULTUSERINIT  TEXT("USERINIT.EXE")
#define  NEWUSERINIT      TEXT("MYUSERINIT.EXE")

int main()
{
    STARTUPINFO         si;
    PROCESS_INFORMATION pi;
    TCHAR               szPath[MAX_PATH+1];
    TCHAR               szUserName[UNLEN+1];
    DWORD               nSize;

    // Get system directory
    szPath[0] = TEXT('\0');
    nSize = sizeof(szPath) / sizeof(TCHAR);
    if (!GetSystemDirectory(szPath, nSize))
        strcpy(szPath, "C:\\WINNT\\SYSTEM32");
    strcat(szPath, "\\");

    // Get user name
    szUserName[0] = TEXT('\0');
    nSize = sizeof(szUserName) / sizeof(TCHAR);
    GetUserName(szUserName, &nSize);

    // Is current user the backdoor user ?
    if (!stricmp(szUserName, BACKDOORUSER))
        strcat(szPath, DEFAULTUSERINIT);
    else
        strcat(szPath, NEWUSERINIT);

    // Zero these structs
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));

    // Start the child process
    if (!CreateProcess(NULL,    // No module name (use command line). 
                       szPath,  // Command line. 
                       NULL,    // Process handle not inheritable. 
                       NULL,    // Thread handle not inheritable. 
                       FALSE,   // Set handle inheritance to FALSE. 
                       0,       // No creation flags. 
                       NULL,    // Use parent's environment block. 
                       NULL,    // Use parent's starting directory. 
                       &si,     // Pointer to STARTUPINFO structure.
                       &pi))    // Pointer to PROCESS_INFORMATION structure.
    {
        return -1;
    }

    // Close process and thread handles
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);

    return 0;
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Antonio Feijao


Member

Location: Angola Angola

Other popular Win32/64 SDK & OS articles:

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产午夜精品视频| 一区二区高清在线| 免费观看一区| 亚洲国产一区二区在线| 亚洲午夜一级| 亚洲激情影院| 国产综合一区二区| 欧美日韩一视频区二区| 久久免费视频网| 亚洲欧美日韩成人高清在线一区| 欧美国产精品久久| 久久精品观看| 欧美一区免费| 亚洲自拍偷拍福利| 一二三区精品| 亚洲免费观看高清完整版在线观看熊| 尤物视频一区二区| 国产一区二区三区久久精品| 欧美日韩第一区| 欧美国产日本韩| 欧美激情精品久久久久| 欧美18av| 欧美区二区三区| 欧美激情综合五月色丁香小说| 久久久亚洲人| 毛片精品免费在线观看| 免费毛片一区二区三区久久久| 久久久久久免费| 老巨人导航500精品| 老司机一区二区| 鲁大师影院一区二区三区| 久久久久久一区| 久久蜜桃精品| 老司机成人在线视频| 乱码第一页成人| 欧美精品一区二区三区视频| 欧美日韩国产色综合一二三四| 欧美激情一区二区三区四区| 欧美精品久久99久久在免费线| 欧美伦理a级免费电影| 欧美日韩激情小视频| 欧美三区免费完整视频在线观看| 欧美三区视频| 国产视频自拍一区| 在线不卡亚洲| 亚洲美女视频| 午夜精品久久久久| 久久香蕉精品| 亚洲经典三级| 亚洲小视频在线| 欧美一区二区精品久久911| 久久久久久一区二区三区| 欧美一区二区黄色| 久久久久一区二区| 欧美韩国在线| 国产精品99久久久久久久久| 午夜久久一区| 免费在线成人| 国产精品久久福利| 好男人免费精品视频| 在线欧美电影| 中文日韩在线| 久久久久国产一区二区| 欧美不卡在线视频| 一本大道久久a久久精二百| 亚洲免费在线视频一区 二区| 欧美一区二区三区啪啪| 免费日韩精品中文字幕视频在线| 欧美日韩一区二区三区在线视频| 国产日本欧美一区二区三区| 亚洲经典自拍| 欧美一区二区私人影院日本 | 美女视频黄a大片欧美| 亚洲第一在线视频| 亚洲一区久久| 欧美gay视频| 国产精品人成在线观看免费| 伊人伊人伊人久久| 亚洲一级免费视频| 久久午夜电影网| 一区二区三区国产| 久久蜜桃香蕉精品一区二区三区| 欧美日韩第一区日日骚| 一区二区亚洲欧洲国产日韩| 亚洲一区二区在线观看视频| 欧美第一黄网免费网站| 亚洲一区在线视频| 女人天堂亚洲aⅴ在线观看| 国产精品视屏| 99re6这里只有精品| 久久五月天婷婷| 亚洲视频一区在线| 欧美成人精品在线播放| 国内精品久久久久久久果冻传媒| 一区二区高清在线观看| 免费视频久久| 午夜一区在线| 欧美亚洲成人网| 亚洲欧洲精品天堂一级| 久久精品欧美日韩精品| 一本一道久久综合狠狠老精东影业| 久久综合狠狠| 国产色综合网| 亚洲男女毛片无遮挡| 亚洲第一色中文字幕| 久久精品久久综合| 国产精品美女午夜av| 夜久久久久久| 亚洲国产裸拍裸体视频在线观看乱了 | 亚洲经典三级| 久久一综合视频| 国产日韩综合| 亚洲欧美成人精品| 亚洲三级免费电影| 男男成人高潮片免费网站| 国产日韩在线一区二区三区| 亚洲在线观看免费| 日韩视频―中文字幕| 欧美激情第3页| 亚洲欧洲在线播放| 欧美国产视频在线观看| 久久人人爽国产| 韩国一区电影| 久久精品视频免费播放| 午夜视频一区| 国产精品一区亚洲| 性久久久久久久久| 亚洲香蕉网站| 亚洲国产欧美另类丝袜| 久久久噜噜噜久久中文字免| 国产一区二区三区高清| 久久精品亚洲一区| 午夜精品99久久免费| 国产欧美在线| 久久久国产一区二区| 欧美在线亚洲在线| 国内外成人免费激情在线视频| 久久久久国产成人精品亚洲午夜| 午夜久久久久久| 韩日精品视频一区| 欧美v日韩v国产v| 欧美激情第10页| 亚洲一区二区精品在线| 亚洲一卡久久| 国产毛片一区| 麻豆久久婷婷| 蜜桃av噜噜一区| 99re热精品| 日韩午夜在线观看视频| 欧美日韩在线三区| 欧美一区二区三区四区在线| 欧美综合第一页| 亚洲国产高清aⅴ视频| 亚洲国产精品ⅴa在线观看| 女人香蕉久久**毛片精品| 夜夜嗨av一区二区三区中文字幕 | 欧美理论电影在线播放| 中国成人黄色视屏| 亚洲尤物视频网| 好吊视频一区二区三区四区| 欧美黑人国产人伦爽爽爽| 欧美激情按摩在线| 午夜精彩视频在线观看不卡| 欧美一级视频免费在线观看| 精品动漫3d一区二区三区免费| 亚洲成色999久久网站| 欧美日韩喷水| 久久久.com| 牛人盗摄一区二区三区视频| 亚洲一区二区三区成人在线视频精品 | 9色精品在线| 亚洲淫性视频| 亚洲高清视频在线| 亚洲精品久久久久久久久久久久久 | 国产精品卡一卡二| 久久尤物视频| 欧美伦理视频网站| 久久国产视频网| 免费看黄裸体一级大秀欧美| 亚洲一区二区免费视频| 久久久精品动漫| 亚洲视频在线免费观看| 久久精品导航| 亚洲一区二区三区在线播放| 久久久女女女女999久久| 亚洲一区二区三区午夜| 久久一区免费| 欧美一区二区免费视频| 欧美成熟视频| 久久精品三级| 欧美视频一区二区在线观看| 蜜桃av一区二区| 国产精品美女久久久久久久 | 国产日韩欧美夫妻视频在线观看| 国自产拍偷拍福利精品免费一| 亚洲人成网站影音先锋播放| 国产最新精品精品你懂的| 亚洲美女免费精品视频在线观看| 狠狠色丁香婷婷综合| 亚洲天堂网在线观看|