Overview of wmi_file.inc

Public Function Summary

Public functions are intended to be called by the code that imports this library.

Name Summary
wmi_file_check_dir_exists
wmi_file_check_file_exists
wmi_file_file_search
wmi_file_filecreationdate
wmi_file_fileinfo
wmi_file_filelist
wmi_file_filesize
wmi_file_fileversion
wmi_file_get_extnfile
wmi_file_is_file_readable
wmi_file_is_file_writeable
wmi_file_is_subdir_readable
wmi_file_is_subdir_writeable
wmi_file_subdir
wmi_filemodifieddate

Public Function Details

wmi_file_check_dir_exists

Named Parameters

dirPath
handle

Code

function wmi_file_check_dir_exists(handle, dirPath)
{
  if(dirPath){
    query = 'Select Caption from Win32_Directory Where Name = ' +
             raw_string(0x22) + dirPath + raw_string(0x22);
  }
  else return(0);

  dirList = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< dirList) || !dirList){
    return(0);
  }

  return(1);
}


# Ex: dirPath = "\\windows\\"

		
top

wmi_file_check_file_exists

Named Parameters

filePath
handle

Code

function wmi_file_check_file_exists(handle, filePath)
{
  if(filePath){
    query = 'Select Name from CIM_DataFile Where Name = ' +
             raw_string(0x22) + filePath + raw_string(0x22);
  }
  else return(0);

  fileList = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< fileList) || !fileList){
    return(0);
  }

  return(1);
}

# Ex: dirPath = "\\WINDOWS\\" and fileName = "Safari" and fileExtn = "exe"

		
top

Named Parameters

dirPath
fileExtn
fileName
handle

Code

function wmi_file_file_search(handle, dirPath, fileName, fileExtn)
{
  if(dirPath && fileName && fileExtn){
    query = 'Select Name from CIM_DataFile Where Path = ' +
             raw_string(0x22) + dirPath + raw_string(0x22) +
            'and FileName = ' + raw_string(0x22) + fileName + raw_string(0x22) +
            'and Extension = ' + raw_string(0x22) + fileExtn + raw_string(0x22);
  }
  else if(fileName && fileExtn){
    query = 'Select Name from CIM_DataFile Where FileName = ' +
             raw_string(0x22) + fileName + raw_string(0x22) +
             'and Extension = ' + raw_string(0x22) + fileExtn + raw_string(0x22);
  }
  else if(fileName)
  {
    query = 'Select Name from CIM_DataFile Where FileName = ' +
             raw_string(0x22) + fileName + raw_string(0x22);
  }
  else return(0);

  fileList = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< fileList) || !fileList){
    return(0);
  }

  return fileList;
}

# Ex: filePath = "c:\\windows\\system32\\cmd.exe"

		
top

wmi_file_filecreationdate

Named Parameters

filePath
handle

Code

function wmi_file_filecreationdate(handle, filePath)
{
  if(filePath){
    query = 'Select CreationDate from CIM_DataFile Where Name = ' +
             raw_string(0x22) + filePath + raw_string(0x22);
  }
  else return(0);

  filePath = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< filePath) || !filePath){
    return(0);
  }

  filePath = ereg_replace(pattern:"\|[.:0-9a-zA-Z \\]+", string:filePath, replace:"");
  return filePath;
}

# Ex: filePath = "c:\\windows\\system32\\cmd.exe"

		
top

wmi_file_fileinfo

Named Parameters

filePath
handle

Code

function wmi_file_fileinfo(handle, filePath)
{
  if(filePath){
    query = 'Select * from CIM_DataFile Where Name = ' +
             raw_string(0x22) + filePath + raw_string(0x22);
  }
  else return(0);

  fileInfo = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< fileInfo) || !fileInfo){
    return(0);
  }

  return wmi_misc_split_res(List:fileInfo);
}

# Ex filePath = "c:\\windows\\system32\\cmd.exe"

		
top

wmi_file_filelist

Named Parameters

dirPath
handle

Code

function wmi_file_filelist(handle, dirPath)
{
  if(dirPath){
    query = 'Select Name from CIM_DataFile Where Path = ' +
             raw_string(0x22) + dirPath + raw_string(0x22);
  }
  else return(0);

  fileList = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< fileList) || !fileList){
    return(0);
  }

  return fileList;
}

# Ex: filePath = "c:\\windows\\system32\\cmd.exe"

		
top

wmi_file_filesize

Named Parameters

filePath
handle

Code

function wmi_file_filesize(handle, filePath)
{
  if(filePath){
    query = 'Select FileSize from CIM_DataFile Where Name = ' +
             raw_string(0x22) + filePath + raw_string(0x22);
  }
  else return(0);

  fileList = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< fileList) || !fileList){
    return(0);
  }

  fileList = ereg_replace(pattern:"\|[.:0-9a-zA-Z \\]+", string:fileList, replace:"");
  return fileList;
}

# Ex: dirPath = "\\Windows\\" and fileExtn ="exe"

		
top

wmi_file_fileversion

Named Parameters

filePath
handle

Code

function wmi_file_fileversion(handle, filePath)
{
  if(filePath){
    query = 'Select Version from CIM_DataFile Where Name = ' +
             raw_string(0x22) + filePath + raw_string(0x22);
  }
  else return(0);

  fileVer = wmi_query(wmi_handle:handle, query:query);

  if((fileVer =~ "NTSTATUS|\(null\)") || !fileVer){
    return(0);
  }

  fileVer = ereg_replace(pattern:"[.:0-9a-zA-Z \\]+\|", string:fileVer, replace:"");
  return fileVer;
}

# Ex: filePath = "c:\\windows\\system32\\cmd.exe"

		
top

wmi_file_get_extnfile

Named Parameters

dirPath
fileExtn
handle

Code

function wmi_file_get_extnfile(handle, dirPath, fileExtn)
{
  if(dirPath && fileExtn){
    query = 'Select Name from CIM_DataFile Where Path = ' +
             raw_string(0x22) + dirPath + raw_string(0x22) +
             'and Extension = ' + raw_string(0x22) + fileExtn + raw_string(0x22);
  }

  else if(fileExtn){
    query = 'Select Name from CIM_DataFile Where Extension = ' +
             raw_string(0x22) + fileExtn + raw_string(0x22);
  }

  else return(0);

  fileExtn = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< fileExtn) || !fileExtn){
    return(0);
  }

  return fileExtn;
}

# Ex: filePath = "c:\\windows\\system32\\cmd.exe"

		
top

wmi_file_is_file_readable

Named Parameters

dirPath
filePath
handle

Code

function wmi_file_is_file_readable(handle, dirPath, filePath)
{
  if(dirPath){
    query = 'Select Readable from CIM_DataFile Where Path = ' +
             raw_string(0x22) + dirPath + raw_string(0x22);
  }
  else if(filePath){
    query = 'Select Readable from CIM_DataFile Where Name = ' +
             raw_string(0x22) + filePath + raw_string(0x22);
  }
  else return(0);

  fileList = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< fileList) || !fileList){
    return(0);
  }

  fileList = ereg_replace(pattern:"\|", string:fileList, replace:" - ");
  return fileList;
}

# Ex: dirPath = "\\windows\\" and filePath = "c:\\windows\\system32\\cmd.exe"

		
top

wmi_file_is_file_writeable

Named Parameters

dirPath
filePath
handle

Code

function wmi_file_is_file_writeable(handle, dirPath, filePath)
{
  if(dirPath){
    query = 'Select Writeable from CIM_DataFile Where Path = ' +
             raw_string(0x22) + dirPath + raw_string(0x22);

  }
  else if(filePath){
    query = 'Select Writeable from CIM_DataFile Where Name = ' +
             raw_string(0x22) + filePath + raw_string(0x22);
  }
  else return(0);

  fileList = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< fileList) || !fileList){
    return(0);
  }

  fileList = ereg_replace(pattern:"\|", string:fileList, replace:" - ");
  return fileList;
}


		
top

wmi_file_is_subdir_readable

Named Parameters

dirPath
handle

Code

function wmi_file_is_subdir_readable(handle, dirPath)
{
  if(dirPath){
    query = 'Select Readable from Win32_Directory Where Path = ' +
             raw_string(0x22) + dirPath + raw_string(0x22);
  }
  else return(0);

  dirList = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< dirList) || !dirList){
    return(0);
  }

  dirList = ereg_replace(pattern:"\|", string:dirList, replace:" - ");
  return dirList;
}

# Ex: dirPath = "\\windows\\"

		
top

wmi_file_is_subdir_writeable

Named Parameters

dirPath
handle

Code

function wmi_file_is_subdir_writeable(handle, dirPath)
{
  if(dirPath){
    query = 'Select Writeable from Win32_Directory Where Path = ' +
             raw_string(0x22) + dirPath + raw_string(0x22);
  }
  else return(0);

  dirList = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< dirList) || !dirList){
    return(0);
  }

  dirList = ereg_replace(pattern:"\|", string:dirList, replace:" - ");
  return dirList;
}

#############################################################################

		
top

wmi_file_subdir

Named Parameters

dirPath
handle

Code

function wmi_file_subdir(handle, dirPath)
{
  if(dirPath){
    query = 'Select Name from Win32_Directory Where Path = ' +
             raw_string(0x22) + dirPath + raw_string(0x22);
  }
  else return(0);

  pathList = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< pathList) || !pathList){
    return(0);
  }

  return pathList;
}

# Ex: dirPath = "C:\\windows\\"

		
top

wmi_filemodifieddate

Named Parameters

filePath
handle

Code

function wmi_filemodifieddate(handle, filePath)
{
  if(filePath){
    query = 'Select LastModified from CIM_DataFile Where Name = ' +
             raw_string(0x22) + filePath + raw_string(0x22);
  }
  else return(0);

  filePath = wmi_query(wmi_handle:handle, query:query);

  if(("NTSTATUS" >< filePath) || !filePath){
    return(0);
  }

  filePath = ereg_replace(pattern:"\|[.:0-9a-zA-Z \\]+", string:filePath, replace:"");
  return filePath;
}

# Ex: dirPath = "\\windows\\" and filePath = "c:\\windows\\system32\\cmd.exe"

		
top