2012-12-12 9 views
5

मैं माइक्रोसॉफ्ट एक्सेस .ldb लॉक फ़ाइल पढ़ने के लिए बैच फ़ाइल बनाने की कोशिश कर रहा हूं। लॉक फ़ाइल में कंप्यूटर नामों और उपयोगकर्ता नामों की एक सूची होती है। मैं कंप्यूटर नाम निकालना चाहता हूं और अंततः उन्हें बाहरी कमांड के खिलाफ चलाता हूं।एमएस एक्सेस पढ़ने के लिए बैच फ़ाइल लिखने में मदद की ज़रूरत है। Null delimiters के साथldb लॉक फ़ाइल

बैच फ़ाइल का स्वरूप है साथ एक ही पंक्ति (1) एक कंप्यूटर का नाम (2) एक नल केरेक्टर (हेक्स 00) (3) लगभग 20 रिक्त स्थान (4) उपयोगकर्ता नाम (5) एक नल चरित्र (6) लगभग 20 रिक्त स्थान दोहराना। (NUL) हेक्स 00 का प्रतिनिधित्व करने के साथ नोटपैड में

उदाहरण ++:

 
COMPUTER0123(NUL)      Admin(NUL)      COMPUTER0507(NUL)      Admin(NUL) 

मैं FOR का उपयोग कर फ़ाइल को पढ़ने के लिए कई तरीकों की कोशिश की है लेकिन अतीत पहले कंप्यूटर का नाम नहीं मिल सकता है।

 
setlocal EnableDelayedExpansion 
set file=database.ldb 

for /F %%a in ('type %file%') do (
    echo %%a 
    ) 

मेरी एक्सेस डेटाबेस के अधिकांश के लिए के लिए, फ़ाइल में उपयोगकर्ता नाम Admin है। मैं FIND का उपयोग करने में सक्षम हूं ताकि मुझे यह बताने के लिए कि "व्यवस्थापक" की कितनी घटनाएं फ़ाइल में हैं (प्लस 1)।

for /f "delims=" %%n in ('find /c /v "Admin" %file%') do set "len=%%n" 
set "len=!len:*:=!" 
echo %len% (minus 1) computer names to process 
<%file% (
    for /l %%l in (1 1 !len!) do ( 
    set "line=" 
    set /p "line=" 
    echo(!line!)  
    ) 
) 

मिली लाइनों के माध्यम से छेड़छाड़ काम नहीं करती है, शायद इसलिए क्योंकि फ़ाइल में केवल एक पंक्ति है (कोई कैरिज रिटर्न नहीं)।

मैं एक समाधान ढूंढना चाहता हूं जो विंडोज एक्सपी के मानक स्थापित के साथ काम करेगा।


एक स्वीकृत उत्तर प्राप्त करने के बाद, मैंने इसे एक बैच फ़ाइल में जोड़ा जो मैं नीचे पोस्ट कर रहा हूं। मैंने फ़ाइल ShowUsersInLDB.bat नाम दिया और इसे अपने SendTo फ़ोल्डर में डाल दिया।

@echo off 
::=================================================================== 
:: Put this in your SendTo folder and it will let you right-click 
:: on an Access .ldb/.laccdb lock file and tell you the computer 
:: names that have opened the database. 
:: 
:: After the computer names are shown, this will prompt you to 
:: search for the user names associated with each computer. This 
:: depends upon finding a 3rd party file named NetUsers.exe in 
:: the user profile folder. Feel free to change the path if you 
:: want to store the file in another location. 
:: 
:: NetUsers.exe can be downloaded from here: http://www.optimumx.com/downloads.html#NetUsers 
:: 
:: Notes: 
:: 1) Keep in mind that sometimes after people leave the database 
:: the lock file still shows their computer name. Don't jump 
:: to conclusions. 
:: 2) NetUsers.exe seems to report all users who have logged on 
:: to the computer and not logged off, including services. 
:: If you aren't familiar with your user names or your users are 
:: sharing remote desktops/Citrix/Terminal Services, you may have 
:: to guess who might have created the lock entry. 
:: 
:: Installation: 
:: You may find a batch file named Install_UsersInLDB.bat that will 
:: copy this file to the SendTo folder and the NetUsers.exe file to 
:: the user profile (or a place you define). 
:: 
:: Ben Sacherich - March 2014 
:: Please let me know if you have any ideas for improvements. 
::=================================================================== 

setlocal 
set file="%1" 

:: Make sure the file has a compatible extension. 
if "%~x1"==".ldb" goto :ExtensionIsValid 
if "%~x1"==".laccdb" goto :ExtensionIsValid 

echo. 
echo "%~n1%~x1" is not the correct file type. 
echo. 
pause 
goto :End 

:ExtensionIsValid 
echo The Access "%~n1%~x1" file contains 
echo the following computer names: 
echo. 
set "compNameLine=1" 
for /f %%A in ('more "%file%"') do (
    if defined compNameLine (
    echo %%A 
    set "compNameLine=" 
) else set "compNameLine=1" 
) 

echo. 
echo Are you ready to look up the user names on each computer? 
pause 

set "compNameLine=1" 
for /f %%A in ('more "%file%"') do (
    if defined compNameLine (
    ::echo %%A 
    "%userprofile%\netusers" \\%%A 
    set "compNameLine=" 
) else set "compNameLine=1" 
) 

echo. 
echo -- Validation finished at %time% 
pause 
:End 
exit 

उत्तर

4

सीएमडी.एक्सईई आमतौर पर एनयूएल बाइट्स के साथ अच्छी तरह से खेल नहीं करता है। लेकिन कुछ बाहरी आदेश हैं जो एनयूएल बाइट्स को संभाल सकते हैं।

आपको "लाइन" की लंबाई के बारे में चिंता करने की भी आवश्यकता है। सीएमडी.एक्सईई 8191 बाइट्स से अधिक लंबी लाइनों को पसंद नहीं करता है।

मुझे लगता है कि आपकी सबसे अच्छी शर्त अधिक है क्योंकि यह एनयूएल को नई लाइनों में परिवर्तित करती है।

निम्नलिखित आपके कंप्यूटर नामों को गूंजना चाहिए।

@echo off 
setlocal 
set "file=database.ldb" 
set "compNameLine=1" 
for /f %%A in ('more "%file%"') do (
    if defined compNameLine (
    echo %%A 
    set "compNameLine=" 
) else set "compNameLine=1" 
) 
+0

मुझे नल पात्रों को संभालने में समस्या का सामना करना पड़ रहा था। अधिक मदद का उपयोग करना। पारितोषिक के लिए धन्यवाद! –

संबंधित मुद्दे