OpendTect  6.6
winutils.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A.H. Lammertink
8  Date: 09-10-2003
9  Contents: Utilities for win32 support
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 
14 -*/
15 
16 
17 #include "basicmod.h"
18 #include "gendefs.h"
19 
20 #ifdef __win__
21 # include "shlobj.h"
22 #endif
23 
24 extern "C"
25 {
26  mGlobal(Basic) const char* getCleanUnxPath( const char* path );
27  mGlobal(Basic) const char* getCleanWinPath( const char* path );
28  mGlobal(Basic) const char* GetSpecialFolderLocation(int csidl);
29 }
30 
31 #ifdef __win__
32 
33 mGlobal(Basic) bool winCopy(const char* from,const char* to,
34  bool isfile,bool ismove=false);
35 mGlobal(Basic) bool winRemoveDir(const char* dirnm);
36 
37 namespace WinUtils {
38 
39 mGlobal(Basic) bool isFileInUse(const char* fnm);
40 mGlobal(Basic) bool belongsToStdUser(const char* fnm);
41 mGlobal(Basic) bool belongsToAdmin(const char* fnm);
42 mGlobal(Basic) bool belongsToTrusterInstaller(const char* fnm);
43 mGlobal(Basic) bool pathContainsTrustedInstaller(const char* fnm);
44 
45  /*<! Depends on the running process
46  Does not return true if the process is
47  not start with elevated privileges */
48 mGlobal(Basic) bool IsUserAnAdmin();
49 mGlobal(Basic) bool NTUserBelongsToAdminGrp();
50 mGlobal(Basic) bool serviceIsRunning(const char* nm);
51  /* See SERVICE_STATUS_PROCESS.dwCurrentState
52  for possible values*/
53 mGlobal(Basic) int getServiceStatus(const char* nm);
54 
55 }
56 
57 #define mDeprecatedMachCmd mDeprecated("Use MachineCommand")
58 
59 mDeprecatedMachCmd mGlobal(Basic) bool executeWinProg(const char* comm,
60  const char* parm,
61  const char* runin=0);
62 mDeprecatedMachCmd mGlobal(Basic) bool execShellCmd(const char* comm,
63  const char* parm,
64  const char* runin );
65 mDeprecatedMachCmd mGlobal(Basic) bool execProc(const char* comm,bool inconsole,
66  bool inbg,const char* runin);
67 
68 mGlobal(Basic) unsigned int getWinVersion();
69 mGlobal(Basic) unsigned int getWinMinorVersion();
70 mGlobal(Basic) const char* getFullWinVersion();
71 mGlobal(Basic) const char* getWinBuildNumber();
72 mGlobal(Basic) const char* getWinDisplayName();
73 mGlobal(Basic) const char* getWinEdition();
74 mGlobal(Basic) const char* getWinProductName();
75 
76 mGlobal(Basic) bool canHaveAppLocker();
77 mGlobal(Basic) bool hasAppLocker();
78 mGlobal(Basic) const char* getCygDir();
79 mGlobal(Basic) bool getDefaultBrowser(BufferString& cmd,
80  BufferString& errmsg);
81 mGlobal(Basic) bool getDefaultApplication( const char* scheme,
82  BufferString& cmd,
83  BufferString& errmsg);
84 
85 mGlobal(Basic) bool setRegKeyVal(const char* ky, const char* vanrnm,
86  const char *val);
87 mGlobal(Basic) bool removeRegKey(const char*);
88 mGlobal(Basic) bool readKey(const HKEY,const char* path,
89  const char* ky,BufferString&,
90  LPDWORD dwFlags=NULL,
91  LPDWORD dwType=NULL);
92 
93 mGlobal(Basic) void disableAutoSleep();
94 mGlobal(Basic) void enableAutoSleep();
95 /*
96 For documentation of the CSIDL values, see:
97 
98 http://msdn.microsoft.com/library/default.asp?
99  url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp
100 
101 
102  CSIDL
103  _________________________________________________________________
104 
105  CSIDL values provide a unique system-independent way to identify
106  special folders used frequently by applications, but which may not
107  have the same name or location on any given system. For example, the
108  system folder may be "C:\Windows" on one system and "C:\Winnt" on
109  another.
110 
111  Constants
112 
113  CSIDL_FLAG_CREATE (0x8000)
114  Version 5.0. Combine this CSIDL with any of the following
115  CSIDLs to force the creation of the associated folder.
116 
117  CSIDL_ADMINTOOLS (0x0030)
118  Version 5.0. The file system directory that is used to store
119  administrative tools for an individual user. The Microsoft
120  Management Console (MMC) will save customized consoles to this
121  directory, and it will roam with the user.
122 
123  CSIDL_ALTSTARTUP (0x001d)
124  The file system directory that corresponds to the user's
125  nonlocalized Startup program group.
126 
127  CSIDL_APPDATA (0x001a)
128  Version 4.71. The file system directory that serves as a common
129  repository for application-specific data. A typical path is
130  C:\Documents and Settings\username\Application Data. This CSIDL
131  is supported by the redistributable Shfolder.dll for systems
132  that do not have the Microsoft Internet Explorer 4.0
133  integrated Shell installed.
134 
135  CSIDL_BITBUCKET (0x000a)
136  The virtual folder containing the objects in the user's Recycle
137  Bin.
138 
139  CSIDL_CDBURN_AREA (0x003b)
140  Version 6.0. The file system directory acting as a staging area
141  for files waiting to be written to CD. A typical path is
142  C:\Documents and Settings\username\Local Settings\Application
143  Data\Microsoft\CD Burning.
144 
145  CSIDL_COMMON_ADMINTOOLS (0x002f)
146  Version 5.0. The file system directory containing
147  administrative tools for all users of the computer.
148 
149  CSIDL_COMMON_ALTSTARTUP (0x001e)
150  The file system directory that corresponds to the nonlocalized
151  Startup program group for all users. Valid only for Microsoft
152  Windows NT systems.
153 
154  CSIDL_COMMON_APPDATA (0x0023)
155  Version 5.0. The file system directory containing application
156  data for all users. A typical path is C:\Documents and
157  Settings\All Users\Application Data.
158 
159  CSIDL_COMMON_DESKTOPDIRECTORY (0x0019)
160  The file system directory that contains files and folders that
161  appear on the desktop for all users. A typical path is
162  C:\Documents and Settings\All Users\Desktop. Valid only for
163  Windows NT systems.
164 
165  CSIDL_COMMON_DOCUMENTS (0x002e)
166  The file system directory that contains documents that are
167  common to all users. A typical paths is C:\Documents and
168  Settings\All Users\Documents. Valid for Windows NT systems and
169  Microsoft Windows 95 and Windows 98 systems with Shfolder.dll
170  installed.
171 
172  CSIDL_COMMON_FAVORITES (0x001f)
173  The file system directory that serves as a common repository
174  for favorite items common to all users. Valid only for Windows
175  NT systems.
176 
177  CSIDL_COMMON_MUSIC (0x0035)
178  Version 6.0. The file system directory that serves as a
179  repository for music files common to all users. A typical path
180  is C:\Documents and Settings\All Users\Documents\My Music.
181 
182  CSIDL_COMMON_PICTURES (0x0036)
183  Version 6.0. The file system directory that serves as a
184  repository for image files common to all users. A typical path
185  is C:\Documents and Settings\All Users\Documents\My Pictures.
186 
187  CSIDL_COMMON_PROGRAMS (0x0017)
188  The file system directory that contains the directories for the
189  common program groups that appear on the Start menu for all
190  users. A typical path is C:\Documents and Settings\All
191  Users\Start Menu\Programs. Valid only for Windows NT systems.
192 
193  CSIDL_COMMON_STARTMENU (0x0016)
194  The file system directory that contains the programs and
195  folders that appear on the Start menu for all users. A typical
196  path is C:\Documents and Settings\All Users\Start Menu. Valid
197  only for Windows NT systems.
198 
199  CSIDL_COMMON_STARTUP (0x0018)
200  The file system directory that contains the programs that
201  appear in the Startup folder for all users. A typical path is
202  C:\Documents and Settings\All Users\Start
203  Menu\Programs\Startup. Valid only for Windows NT systems.
204 
205  CSIDL_COMMON_TEMPLATES (0x002d)
206  The file system directory that contains the templates that are
207  available to all users. A typical path is C:\Documents and
208  Settings\All Users\Templates. Valid only for Windows NT
209  systems.
210 
211  CSIDL_COMMON_VIDEO (0x0037)
212  Version 6.0. The file system directory that serves as a
213  repository for video files common to all users. A typical path
214  is C:\Documents and Settings\All Users\Documents\My Videos.
215 
216  CSIDL_CONTROLS (0x0003)
217  The virtual folder containing icons for the Control Panel
218  applications.
219 
220  CSIDL_COOKIES (0x0021)
221  The file system directory that serves as a common repository
222  for Internet cookies. A typical path is C:\Documents and
223  Settings\username\Cookies.
224 
225  CSIDL_DESKTOP (0x0000)
226  The virtual folder representing the Windows desktop, the root
227  of the namespace.
228 
229  CSIDL_DESKTOPDIRECTORY (0x0010)
230  The file system directory used to physically store file objects
231  on the desktop (not to be confused with the desktop folder
232  itself). A typical path is C:\Documents and
233  Settings\username\Desktop.
234 
235  CSIDL_DRIVES (0x0011)
236  The virtual folder representing My Computer, containing
237  everything on the local computer: storage devices, printers,
238  and Control Panel. The folder may also contain mapped network
239  drives.
240 
241  CSIDL_FAVORITES (0x0006)
242  The file system directory that serves as a common repository
243  for the user's favorite items. A typical path is C:\Documents
244  and Settings\username\Favorites.
245 
246  CSIDL_FONTS (0x0014)
247  A virtual folder containing fonts. A typical path is
248  C:\Windows\Fonts.
249 
250  CSIDL_HISTORY (0x0022)
251  The file system directory that serves as a common repository
252  for Internet history items.
253 
254  CSIDL_INTERNET (0x0001)
255  A virtual folder representing the Internet.
256 
257  CSIDL_INTERNET_CACHE (0x0020)
258  Version 4.72. The file system directory that serves as a common
259  repository for temporary Internet files. A typical path is
260  C:\Documents and Settings\username\Local Settings\Temporary
261  Internet Files.
262 
263  CSIDL_LOCAL_APPDATA (0x001c)
264  Version 5.0. The file system directory that serves as a data
265  repository for local (nonroaming) applications. A typical path
266  is C:\Documents and Settings\username\Local
267  Settings\Application Data.
268 
269  CSIDL_MYDOCUMENTS (0x000c)
270  Version 6.0. The virtual folder representing the My Documents
271  desktop item.
272 
273  CSIDL_MYMUSIC (0x000d)
274  The file system directory that serves as a common repository
275  for music files. A typical path is C:\Documents and
276  Settings\User\My Documents\My Music.
277 
278  CSIDL_MYPICTURES (0x0027)
279  Version 5.0. The file system directory that serves as a common
280  repository for image files. A typical path is C:\Documents and
281  Settings\username\My Documents\My Pictures.
282 
283  CSIDL_MYVIDEO (0x000e)
284  Version 6.0. The file system directory that serves as a common
285  repository for video files. A typical path is C:\Documents and
286  Settings\username\My Documents\My Videos.
287 
288  CSIDL_NETHOOD (0x0013)
289  A file system directory containing the link objects that may
290  exist in the My Network Places virtual folder. It is not the
291  same as CSIDL_NETWORK, which represents the network namespace
292  root. A typical path is C:\Documents and
293  Settings\username\NetHood.
294 
295  CSIDL_NETWORK (0x0012)
296  A virtual folder representing Network Neighborhood, the root of
297  the network namespace hierarchy.
298 
299  CSIDL_PERSONAL (0x0005)
300  Version 6.0. The virtual folder representing the My Documents
301  desktop item. This is equivalent to CSIDL_MYDOCUMENTS.
302 
303  Previous to Version 6.0. The file system directory used to
304  physically store a user's common repository of documents. A
305  typical path is C:\Documents and Settings\username\My
306  Documents. This should be distinguished from the virtual My
307  Documents folder in the namespace. To access that virtual
308  folder, use SHGetFolderLocation, which returns the ITEMIDLIST
309  for the virtual location, or refer to the technique described
310  in Managing the File System.
311 
312  CSIDL_PRINTERS (0x0004)
313  The virtual folder containing installed printers.
314 
315  CSIDL_PRINTHOOD (0x001b)
316  The file system directory that contains the link objects that
317  can exist in the Printers virtual folder. A typical path is
318  C:\Documents and Settings\username\PrintHood.
319 
320  CSIDL_PROFILE (0x0028)
321  Version 5.0. The user's profile folder. A typical path is
322  C:\Documents and Settings\username. Applications should not
323  create files or folders at this level; they should put their
324  data under the locations referred to by CSIDL_APPDATA or
325  CSIDL_LOCAL_APPDATA.
326 
327  CSIDL_PROFILES (0x003e)
328  Version 6.0. The file system directory containing user profile
329  folders. A typical path is C:\Documents and Settings.
330 
331  CSIDL_PROGRAM_FILES (0x0026)
332  Version 5.0. The Program Files folder. A typical path is
333  C:\Program Files.
334 
335  CSIDL_PROGRAM_FILES_COMMON (0x002b)
336  Version 5.0. A folder for components that are shared across
337  applications. A typical path is C:\Program Files\Common. Valid
338  only for Windows NT, Windows 2000, and Windows XP systems. Not
339  valid for Windows Millennium Edition (Windows Me).
340 
341  CSIDL_PROGRAMS (0x0002)
342  The file system directory that contains the user's program
343  groups (which are themselves file system directories). A
344  typical path is C:\Documents and Settings\username\Start
345  Menu\Programs.
346 
347  CSIDL_RECENT (0x0008)
348  The file system directory that contains shortcuts to the user's
349  most recently used documents. A typical path is C:\Documents
350  and Settings\username\My Recent Documents. To create a shortcut
351  in this folder, use SHAddToRecentDocs. In addition to creating
352  the shortcut, this function updates the Shell's list of recent
353  documents and adds the shortcut to the My Recent Documents
354  submenu of the Start menu.
355 
356  CSIDL_SENDTO (0x0009)
357  The file system directory that contains Send To menu items. A
358  typical path is C:\Documents and Settings\username\SendTo.
359 
360  CSIDL_STARTMENU (0x000b)
361  The file system directory containing Start menu items. A
362  typical path is C:\Documents and Settings\username\Start Menu.
363 
364  CSIDL_STARTUP (0x0007)
365  The file system directory that corresponds to the user's
366  Startup program group. The system starts these programs
367  whenever any user logs onto Windows NT or starts Windows 95. A
368  typical path is C:\Documents and Settings\username\Start
369  Menu\Programs\Startup.
370 
371  CSIDL_SYSTEM (0x0025)
372  Version 5.0. The Windows System folder. A typical path is
373  C:\Windows\System32.
374 
375  CSIDL_TEMPLATES (0x0015)
376  The file system directory that serves as a common repository
377  for document templates. A typical path is C:\Documents and
378  Settings\username\Templates.
379 
380  CSIDL_WINDOWS (0x0024)
381  Version 5.0. The Windows directory or SYSROOT. This corresponds
382  to the %windir% or %SYSTEMROOT% environment variables. A
383  typical path is C:\Windows.
384 
385  Remarks
386 
387  These values supersede the use of environment variables for this
388  purpose.
389 
390  A CSIDL is used in conjunction with one of four Shell functions,
391  SHGetFolderLocation, SHGetFolderPath, SHGetSpecialFolderLocation,
392  and SHGetSpecialFolderPath, to retrieve a special folder's path or
393  pointer to an item identifier list (PIDL).
394 
395  Combine CSIDL_FLAG_CREATE with any of the other CSIDLs to force the
396  creation of the associated folder. The remaining CSIDLs correspond
397  to either file system folders or virtual folders. Where the CSIDL
398  identifies a file system folder, a commonly used path is given as
399  an example. Other paths may be used. Some CSIDLs can be mapped to
400  an equivalent %VariableName% environment variable. CSIDLs are more
401  reliable, however, and should be used if possible.
402 
403 */
404 
405 #endif /* __win__ */
406 
Conv::to
T to(const F &fr)
Definition: convert.h:34
mGlobal
#define mGlobal(module)
Definition: commondefs.h:180
GetSpecialFolderLocation
const char * GetSpecialFolderLocation(int csidl)
gendefs.h
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
File::isFileInUse
bool isFileInUse(const char *fnm)
getCleanUnxPath
const char * getCleanUnxPath(const char *path)
getCleanWinPath
const char * getCleanWinPath(const char *path)

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2021