473,616 Members | 2,835 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File Owner

I know that that topic may be old to you but I looked at other more-
than-two-year-old topics
related to mine. However, I didn't find them working for my project
at all because its errors return back to me everytime.
The error I have on that project said:

"An unhandled exception of type 'System.EntryPo intNotFoundExce ption'
occurred in TestSysaudit.ex e
Additional information: Unable to find an entry point named
GetFileSecurity in DLL advapi32.dll."
Here what I have on my project: (Remember this project is under VB
and
don't have a window form because of an executable file that run
everyday). I am appreciate that if you guys help me out on solving
the problem.
Option Explicit On
Imports System
Imports System.Text
Imports Scripting
Module Module1
Const OWNER_SECURITY_ INFORMATION As Long = &H1
Const ERROR_INSUFFICI ENT_BUFFER As Long = 122
Private Declare Function GetFileSecurity Lib "advapi32.d ll" ( _
ByVal lpFileName As String, _
ByVal RequestedInform ation As Long, _
ByRef pSecurityDescri ptor As Byte, _
ByVal nLength As Long, _
ByVal lpnLengthNeeded As Long) _
As Long
Private Declare Function GetSecurityDesc riptorOwner Lib
"advapi32.d ll" ( _
ByRef ppSecurityDescr iptor As Byte, _
ByVal ppOwner As Long, _
ByVal lpbOwnerDefault ed As Long) _
As Long
Private Declare Function LookupAccountSi d Lib "advapi32.d ll" ( _
ByVal lpSystemName As String, _
ByVal Sid As Long, _
ByVal name As String, _
ByRef cbName As Long, _
ByVal ReferencedDomai nName As String, _
ByRef cbReferencedDom ainName As Long, _
ByRef peUse As Long) _
As Long
Function GetFileOwner(By Val szfilename As String) As String
Dim bSuccess As Long ' Status variable
Dim sizeSD As Long ' Buffer size to store
Owner's SID
Dim pOwner As Long ' Pointer to the Owner's SID
Dim ownerName As String ' Name of the file owner
Dim domain_name As String ' Name of the first domain
for the owner
Dim name_len As Long ' Required length for the
owner name
Dim domain_len As Long ' Required length for the
domain name
Dim sdBuf() As Byte ' Buffer for Security
Descriptor
Dim nLength As Long ' Length of the Windows
Directory
Dim deUse As Long ' Pointer to a SID_NAME_USE
enumerated type
' indicating the type of the account
' Call GetFileSecurity the first time to obtain the size of
the buffer
' required for the Security Descriptor.
bSuccess = GetFileSecurity (szfilename,
OWNER_SECURITY_ INFORMATION, 0, 0, sizeSD)
' exit if any error
If (bSuccess = 0) And (Err.LastDllErr or <>
ERROR_INSUFFICI ENT_BUFFER) Then _
Exit Function
' Create a buffer of the required size and call
GetFileSecurity again
ReDim sdBuf(sizeSD - 1)
' Fill the buffer with the security descriptor of the object
specified by
' the filename parameter. The calling process must have the
right to view the
' specified aspects of the object's security status.
bSuccess = GetFileSecurity (szfilename,
OWNER_SECURITY_ INFORMATION, sdBuf(0), _
sizeSD, sizeSD)
' exit if error
If bSuccess = 0 Then Exit Function
' Obtain the owner's SID from the Security Descriptor, exit
if
error
bSuccess = GetSecurityDesc riptorOwner(sdB uf(0), pOwner, 0)
If bSuccess = 0 Then Exit Function
' Allocate the required space in the name and domain_name
string variables.
' Allocate 1 byte less to avoid the appended NULL character.
ownerName = Space(name_len - 1)
domain_name = Space(domain_le n - 1)
' Retrieve the name of the account and the name of the first
domain on
' which this SID is found. Passes in the Owner's SID
obtained
previously.
' Call LookupAccountSi d twice, the first time to obtain the
required size
' of the owner and domain names.
bSuccess = LookupAccountSi d(vbNullString, pOwner, ownerName,
name_len, _
domain_name, domain_len, deUse)
' exit if any error
If (bSuccess = 0) And (Err.LastDllErr or <>
ERROR_INSUFFICI ENT_BUFFER) Then _
Exit Function
' Call LookupAccountSi d again to actually fill in the name of
the owner
' and the first domain.
bSuccess = LookupAccountSi d(vbNullString, pOwner, ownerName,
name_len, _
domain_name, domain_len, deUse)
If bSuccess = 0 Then Exit Function
' we've found a result
GetFileOwner = ownerName
End Function
Public Sub Main()
Dim fldrPathName, fname, fowner As String
Dim fso As New FileSystemObjec t
Dim fldr As Folder
Dim fil As File
Dim fmodified, tdate As Date
Dim cur_date, run_date As String
Dim file_name As String
Dim filecnt As Integer
file_name = "c:\printou t" & Year(Now()) &
Format(Month(No w()),
"00") & Format(Day(Now( )), "00")
System.IO.File. Delete(file_nam e)
Dim file As New System.IO.Strea mWriter(file_na me)
cur_date = Format(Now(), "General Date")
file.WriteLine( "Date - " & cur_date)
tdate = DateAdd(DateInt erval.Day, -2, Now())
run_date = Format(tdate, "General Date")
file.WriteLine( " Files Modified Since - " &
run_date)
file.WriteLine( "")
' Lets look for files that are newly modified last 48 hours
file.WriteLine( "Files in C:\")
fldrPathName = ("c:\")
fldr = fso.GetFolder(f ldrPathName)
For Each fil In fldr.Files
fname = fil.Name
fmodified = fil.DateLastMod ified
fowner = GetFileOwner(fn ame)
If fmodified tdate Then
file.WriteLine( " " & fowner & " " & fname & " " &
Format(fmodifie d, "General Date"))
file.WriteLine( "")
End If
Next
file.Close()
End Sub
End Module

Mar 15 '07 #1
2 3429
Keep in mind that "Function" is actually named "FunctionA" or "FunctionW"
in the DLL when it accepts strings as it have two flavors depending on
wether you want to use ansi or unicode.

It's likely you forgot the Alias "GetFileSecurit yA" clause.

---
Patrice

<le****@gmail.c oma écrit dans le message de news:
11************* *********@o5g20 00...legro ups.com...
>I know that that topic may be old to you but I looked at other more-
than-two-year-old topics
related to mine. However, I didn't find them working for my project
at all because its errors return back to me everytime.
The error I have on that project said:

"An unhandled exception of type 'System.EntryPo intNotFoundExce ption'
occurred in TestSysaudit.ex e
Additional information: Unable to find an entry point named
GetFileSecurity in DLL advapi32.dll."
Here what I have on my project: (Remember this project is under VB
and
don't have a window form because of an executable file that run
everyday). I am appreciate that if you guys help me out on solving
the problem.
Option Explicit On
Imports System
Imports System.Text
Imports Scripting
Module Module1
Const OWNER_SECURITY_ INFORMATION As Long = &H1
Const ERROR_INSUFFICI ENT_BUFFER As Long = 122
Private Declare Function GetFileSecurity Lib "advapi32.d ll" ( _
ByVal lpFileName As String, _
ByVal RequestedInform ation As Long, _
ByRef pSecurityDescri ptor As Byte, _
ByVal nLength As Long, _
ByVal lpnLengthNeeded As Long) _
As Long
Private Declare Function GetSecurityDesc riptorOwner Lib
"advapi32.d ll" ( _
ByRef ppSecurityDescr iptor As Byte, _
ByVal ppOwner As Long, _
ByVal lpbOwnerDefault ed As Long) _
As Long
Private Declare Function LookupAccountSi d Lib "advapi32.d ll" ( _
ByVal lpSystemName As String, _
ByVal Sid As Long, _
ByVal name As String, _
ByRef cbName As Long, _
ByVal ReferencedDomai nName As String, _
ByRef cbReferencedDom ainName As Long, _
ByRef peUse As Long) _
As Long
Function GetFileOwner(By Val szfilename As String) As String
Dim bSuccess As Long ' Status variable
Dim sizeSD As Long ' Buffer size to store
Owner's SID
Dim pOwner As Long ' Pointer to the Owner's SID
Dim ownerName As String ' Name of the file owner
Dim domain_name As String ' Name of the first domain
for the owner
Dim name_len As Long ' Required length for the
owner name
Dim domain_len As Long ' Required length for the
domain name
Dim sdBuf() As Byte ' Buffer for Security
Descriptor
Dim nLength As Long ' Length of the Windows
Directory
Dim deUse As Long ' Pointer to a SID_NAME_USE
enumerated type
' indicating the type of the account
' Call GetFileSecurity the first time to obtain the size of
the buffer
' required for the Security Descriptor.
bSuccess = GetFileSecurity (szfilename,
OWNER_SECURITY_ INFORMATION, 0, 0, sizeSD)
' exit if any error
If (bSuccess = 0) And (Err.LastDllErr or <>
ERROR_INSUFFICI ENT_BUFFER) Then _
Exit Function
' Create a buffer of the required size and call
GetFileSecurity again
ReDim sdBuf(sizeSD - 1)
' Fill the buffer with the security descriptor of the object
specified by
' the filename parameter. The calling process must have the
right to view the
' specified aspects of the object's security status.
bSuccess = GetFileSecurity (szfilename,
OWNER_SECURITY_ INFORMATION, sdBuf(0), _
sizeSD, sizeSD)
' exit if error
If bSuccess = 0 Then Exit Function
' Obtain the owner's SID from the Security Descriptor, exit
if
error
bSuccess = GetSecurityDesc riptorOwner(sdB uf(0), pOwner, 0)
If bSuccess = 0 Then Exit Function
' Allocate the required space in the name and domain_name
string variables.
' Allocate 1 byte less to avoid the appended NULL character.
ownerName = Space(name_len - 1)
domain_name = Space(domain_le n - 1)
' Retrieve the name of the account and the name of the first
domain on
' which this SID is found. Passes in the Owner's SID
obtained
previously.
' Call LookupAccountSi d twice, the first time to obtain the
required size
' of the owner and domain names.
bSuccess = LookupAccountSi d(vbNullString, pOwner, ownerName,
name_len, _
domain_name, domain_len, deUse)
' exit if any error
If (bSuccess = 0) And (Err.LastDllErr or <>
ERROR_INSUFFICI ENT_BUFFER) Then _
Exit Function
' Call LookupAccountSi d again to actually fill in the name of
the owner
' and the first domain.
bSuccess = LookupAccountSi d(vbNullString, pOwner, ownerName,
name_len, _
domain_name, domain_len, deUse)
If bSuccess = 0 Then Exit Function
' we've found a result
GetFileOwner = ownerName
End Function
Public Sub Main()
Dim fldrPathName, fname, fowner As String
Dim fso As New FileSystemObjec t
Dim fldr As Folder
Dim fil As File
Dim fmodified, tdate As Date
Dim cur_date, run_date As String
Dim file_name As String
Dim filecnt As Integer
file_name = "c:\printou t" & Year(Now()) &
Format(Month(No w()),
"00") & Format(Day(Now( )), "00")
System.IO.File. Delete(file_nam e)
Dim file As New System.IO.Strea mWriter(file_na me)
cur_date = Format(Now(), "General Date")
file.WriteLine( "Date - " & cur_date)
tdate = DateAdd(DateInt erval.Day, -2, Now())
run_date = Format(tdate, "General Date")
file.WriteLine( " Files Modified Since - " &
run_date)
file.WriteLine( "")
' Lets look for files that are newly modified last 48 hours
file.WriteLine( "Files in C:\")
fldrPathName = ("c:\")
fldr = fso.GetFolder(f ldrPathName)
For Each fil In fldr.Files
fname = fil.Name
fmodified = fil.DateLastMod ified
fowner = GetFileOwner(fn ame)
If fmodified tdate Then
file.WriteLine( " " & fowner & " " & fname & " " &
Format(fmodifie d, "General Date"))
file.WriteLine( "")
End If
Next
file.Close()
End Sub
End Module

Mar 15 '07 #2
Okay I have been changed from:

Private Declare Function GetFileSecurity Lib "advapi32.d ll" ( _

to

Private Declare Function GetFileSecurity Lib "advapi32.d ll" Alias
"GetFileSecurit yA" ( _

And I encountered another error message said:

"An unhandled exception of type 'System.IndexOu tOfRangeExcepti on'
occurred in TestSysaudit.ex e

Additional information: Index was outside the bounds of the array."

Okay, I fixed that problem and had to replace all "Long" into
"Integer". And none of the problem show up but the owner of a file
didn't write into the output file 'printout'.

The output file show:

test.txt 3/15/2007 8:54:17 AM

which should show up as:

admin test.txt 3/15/2007 8:54:17 AM

I would be appreciated that if you help me out what I did wrong or
miss something important.

Mar 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3650
by: pdav | last post by:
Hi! Is there any solution to create a directory with one script with mkdir(), and then write a file (or move an uploaded file) in this directory with another script? The problem is, that the directory belongs to the PHP-interpreter (UID 33 in my case) and the script doing the file creation and the one creating the directory belong to the FTP-user (UID 754 in my case).
10
2819
by: Steve | last post by:
Hi all i am just starting to get back into VB and i need a little help. I am writing a program that asks a user to type in a set of numbers/letters (in this case shipping containers). Once the data is entered i have my 4 letters and i want to be able to call up data relating to the 4 letters. Basically i want it to show who the container belongs to and any other data i wish to put in there relating to the container.
1
1848
by: Ajay | last post by:
hi! i have an application that allows admin users to create template files, which are stored on the server. currently the file are created with the owner "nobody" is it possibly to change the owner to be the same as the owner of the web account? if yes, are there any security risks with doing so - the script changes to the web account's owner, creates the file and then changes back.
2
5037
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified folder structure and naming conventions and then send a Net send message to those users telling them to rectify. The information I want to get is when you select the file/folder and then: Properties -> Security Tab -> Advanced Button -> Owner Tab ->...
6
6782
by: kai rosenthal | last post by:
Hello, with ls -l on windows I get -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile How can I get on windows with a standard python 2.2 (without windows extensions) the information "500" and "everyone" (owner and group)? Also I cannot use popen('ls -l'). With
4
2289
by: tasahmed | last post by:
Hello Friends, I wrote a function which scans the current working directory and lists out details such as directory/file owner, permission etc. The output of this script can be viewing in the monitor when I give the command print_r which is printed out in a array format. The problem I facing is I want this output in a text file, but I have tried so many things it is not working I am copying my code below, I need help in this urgently....
3
8279
by: eholz1 | last post by:
Hello PHP Group, I am having trouble setting permissions correctly so that the magickwand api (php 5.2) can read and write images. I usually read a file from one directory, create a magickwand resource from that file, and transform the image, and save the new image with a new name to a different directory. I have seen that my file and folder permissions when set incorrectly,
1
2911
by: ahammad | last post by:
Hello, I have an XML file that I need to extract data from. The file has multiple lines, one of which contains the following tag: <Owner> owner's name goes here </Owner> I need to be able to extract the owner's name from the XML file. I have never programmed Perl before, but I have a pretty strong background in C/C++ and Java. You're probably wondering why the hell I'm jumping into this with no experience in Perl...it wasn't my choice,...
3
8076
by: Okonita | last post by:
Hi all, I am having problem completing this restore operation. "db2 restore database AAMI01 from /pap/data/backups taken at 20071002130554 to /pap/data/db01 into AAMI01 NEWLOGPATH /pap/data/new/ log WITH 2 BUFFERS BUFFER 1024" SQL1326N The file or directory "/pap/data/db01/" cannot be accessed. The file, directory and path all exist. I created them. I just can't
0
8642
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8592
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8448
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7118
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5550
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4060
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4140
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1439
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.