Shell.Application
یک شئ Folder برای پوشه مشخص شده ایجاد و برمی گرداند
retVal=Shell.NameSpace(vdir)
vDir :
پوشه ای که در آن شئ Folder ایجاد می شود.می تواند رشته ای باشد که مسیر پوشه یا یکی از مقادیر ShellSpecialFolderConstants را مشخص می کند. توجه کنید که نام های ثابت موجود در ShellSpecialFolderConstants در Visual Basic در دسترس هستند ، اما در VBScript یا JScript موجود نیستند. در این موارد ، مقادیر عددی باید در جای خود استفاده شوند.
VB :
Object reference to the Folder object for the specified folder. If the folder is not successfully created, this value returns null.
شئ Folder :
Represents a Shell folder. This object contains properties and methods that allow you to retrieve information about the folder.
The Folder object has these types of members:
یکی از متدها ParseName :
یک شئ FolderItem را که نشان دهنده یک آیتم مشخص است را ایجاد و برمی گرداند.
Set objFolder=objShell.NameSpace("C:\Windows")
if Not (objFolder Is Nothing) Then
Set objFolderItem=objFolder.ParseName("clock.avi")
'اضافه کردن کد در اینجا
Set objFolderItem=Nothing
End If
شماری از ویژگیهای شئ FolderItem :
GetFolder
GetLink
IsFileSystem
IsFolder
IsLink
Name
Path
Size
Type
متغیرهایی تعریف شده که زمان ارجاع به آن راحت باشید و مقادیری را به آن تخصیص بدهید با Private Type و مشخص کردن نام و دیتا تایپ آن.
Private Type CUSTOM_MSGBOX lTimeout As Long
lExitButton As Long
lInterval As Long
strPrompt As String
End Type
ClassName = Space(256)
' Make sure we spotted a messagebox (dialog)
Private hHook As Long
Public hwndMsgBox As Long
Public lTimerHandle As Long
Public hAppInstance As Long
این یک نمونه کار است هر زمان که توابع API را مطالعه کردید می توانید با چیدمان درست کدها به مقاصد خود دست یابید البته هوک کردن مشکل است اگر خطایی اتفاق بیافتد سیستم هنگ خواهد کرد به WSCRIP.SHELL و POPUT هم می توان مراجعه کرد .
CREATEOBJECT("WSCRIPT.SHELL")
OBJECT.POPUP
Wscript Popup Method vbsedit
Echo Method vbsedit
Wscript.Shell + Shell.Application Objects shell.html
فرضا ساختن مرجع آبجکت یا شئ به یک فولدر با متد NAMESPACE از آبجکت SHELL.APPLICATION
FolderItems.Count property :
Contains the number of items in the collection.
ssfWINDOWS = 36
Dim objShell,objFolder As Object
Set objShell =CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(ssfWINDOWS)
Set objFolderItems = objFolder.Items
nCount = objFolderItems.Count
عملی را روی فایل خاصی انجام میدهد.
مثل Edit ، Open یا Explore ، Print و جنس آن از نوع String است.
طبق روش زیر برای ویندوز ۶۴ بیت قبل از فانکشن PtrSafe قرار گرفته بغیر از hWnd که نمایانگر پنجره است و nShowCmd که نمایانگر نمایش پنجره در وضعیت هایی است و از نوع عددی ( Long ) هستند بقیه پارامترها از نوع String می باشند.
#If VBA7 Then
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#Else
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#End If
lpFile specifies a document file, lpParameters should be NULL.
اگر lpFile سندی را مشخص کند lpParameters نمی تواند Null باشد.
The flags that specify how an application is to be displayed when it is opened. If lpFile specifies a document file,
nShow مشخص میکند چگونه یک اپلیکیشن زمانیکه باز میشود نمایش داده شود اگر lpFile یک فایلی مثل Word را مشخص نماید.
If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value that indicates the cause of the failure.
اگر تابع درست انجام شود یک مقداری بزرگتر از ۳۲ را برمی گرداند می توانید با Msgbox در اکسس ببینید و اگر Fail دهد یا درست انجام نشود مقداری که علت انجام نشدنش باشد را نشان می دهد فرضا اگر دسترسی به فایل نداشته باشیم.
مثال بالا که از سایت گرفته شده نمایانگر این است که اگر دسترسی به فایلی امکانپذیر نبود بعلت محدودیت از طرف ادمین جعبه پیامی را باز کرده و به شما اعلام می نماید. ( GetDeskTopWindow یک هندل است که می بایست تابع آنرا در Module اضافه کنید در اینترنت تابع مورد نظر موجود است حتما از CloseHandle استفاده کنید.
Constant | Value | Description |
vbHide | 0 | Window is hidden and focus is passed to the hidden window. |
vbNormalFocus | 1 | Window has focus and is restored to its original size and position. |
vbMinimizedFocus | 2 | Window is displayed as an icon with focus. |
vbMaximizedFocus | 3 | Window is maximized with focus. |
vbNormalNoFocus | 4 | Window is restored to its most recent size and position. The currently active window remains active. |
vbMinimizedNoFocus | 6 | Window is displayed as an icon. The currently active window remains active. |
Set the registry flag to display Hidden and System files in Windows Explorer
WScript.Shell
_"myKey="HKCU\Software\Microsoft\Windows
"\CurrentVersion\Explorer\Advanced\Hidden\"
"WshShell.RegWrite myKey,1,"REG_DWORD
Methods .AppActivate 'Activate running command. .Run 'Run an application .TileVertically 'Tile app windows .RegRead 'Read from registry .RegDelete 'Delete from registry .RegWrite 'Write to the registry
"Shell.Application" Methods .CanStartStopService("ServiceName") 'Can the current user start/stop the named service? .CascadeWindows 'Arrange app windows .EjectPC 'Eject PC from a docking station .Explore(FolderPath) 'Open a folder .FileRun 'Open the File-run dialogue .GetSystemInformation("PhysicalMemoryInstalled") 'Physical memory installed, in bytes. .IsServiceRunning("ServiceName") 'Check if a Windows service is running .MinimizeAll 'Minimize everything .NameSpace("C:\\") 'Create an object reference to a folder .ServiceStart("ServiceName", true) 'Start a windows service .ServiceStop("ServiceName", true) 'Stop a windows service .SetTime 'Open the set time GUI .ShellExecute 'Run a script or application .ShutdownWindows .TileHorizontally 'Tile app windows .TileVertically 'Tile app windows .ToggleDesktop 'Show/Hide Desktop .TrayProperties 'Display the Taskbar/Start Menu Properties .UndoMinimizeAll 'Un-Minimize everything
Shell.Application
ساخت آبجکت بالا
("\\:Shell.Open("C.
ثابت های فولدرهای خاص یا SpecialFolder
Desktop 0
Cookies 33
DesktopDirectory 16
Favorites 6
Fonts 20
History 34
MyComputer 17
MyDocuments 5
MyMusic 13
MyPictures 39
MyVideos 14
ProgramFiles 38
ProgramFilesX86 42
Recent 8
StartMenu 11
Startup 7
System 37
Windows 36
Shell.Application
برای دسترسی به آیتم یا آیتم های فولدرهای خاص استفاده از متد شی Folder که Items هست
متد CopyHere ... آیتم یا آیتم هایی را به فولدراضافه میکند
("CopyHere("C:\AUTOEXEC.BAT.
مثال : ثابت هگزا H14& یا دسیمال 20 ( حاصل 1 ×16+4) برای فولدر Fonts
(NameSpace(&H14.