Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Problems creating a network share during setup


2 replies to this topic

Valerio

Valerio
  • Members
  • 3 posts

Posted 27 August 2001 - 10:36

Hi,
i need to create a network share during installation, so i'm trying to use the NetShareAdd function from the Win32 API inside my IScript CA.

This function is prototyped this way in C (from MSDN):

-------------------------------------------------------------------------
Windows NT/2000 or later: The parameter order is as follows.

NET_API_STATUS NetShareAdd(
 LPWSTR servername,
 DWORD level,      
 LPBYTE buf,        
 LPDWORD parm_err  
);
Windows 95/98/Me: You must specify the size of the information buffer, in bytes, using the cbBuffer parameter. The Windows NT/Windows 2000 parm_err parameter is not available on this platform. Therefore, the parameter list is as follows.

extern API_FUNCTION
NetShareAdd(
 const char FAR * pszServer,      
 short sLevel,                    
 const char FAR * pbBuffer,        
 unsigned short  cbBuffer          
);
-------------------------------------------------------------------------

My script works for NT/2000, but it fails under Win9X (have tried only win95, but i think its the same in Win98/ME). I think the reason is i'm wrong with the prototyping, coz the setup immediately initiate rollback when i call the SVRAPI.NetShareAdd function. I remember from previous experiences that this could happen when prototype is wrong. But ..... i don't see anything wrong with my prototype, so any help will be very appreciated :))))

This is my Win9x function for the custom action :

--------------------------------------------------------------------------

prototype LONG SVRAPI.NetShareAdd ( POINTER, LONG, POINTER, LONG );

// windows9x only
#define LM20_NNLEN  12                  // LM 2.0 Net name length
#define SHPWLEN     8                   // Share password length (bytes)
#defineSHI50F_FULL0x0002

typedef _SHARE_INFO_50
begin
 STRING        shi50_netname[LM20_NNLEN+1];
 CHAR   shi50_type;
 NUMBERshi50_flags;
 LPSTR    shi50_remark;
 LPSTRshi50_path;
 STRING        shi50_rw_password[SHPWLEN+1];
 STRING        shi50_ro_password[SHPWLEN+1];
end;

////////////////////////////////////////////////////////////////////////////////
// W9X only
// share a directory providing szShareName (need _NetShareConnect to be called first)
////////////////////////////////////////////////////////////////////////////////
function _NetShareCreate9x (szShareName, szPath)
STRING szDLL,buff,szPathUpper;
   _SHARE_INFO_50 NewShare;
   _SHARE_INFO_50 POINTER pNewShare;
POINTER pDirPathNoWide;
LONG res, cbBuffer;
begin
#ifdef __DEBUG__
MessageBox ("in NETSHAREADD_9X",INFORMATION);
#endif

  szDLL   = WINSYSDIR ^ DLL_NETAPI_9X;
#ifdef __DEBUG__
MessageBox ("szDLL = " + szDLL,INFORMATION);
#endif

res = UseDLL ( szDLL );
if (res < 0) then
 MessageBox(ERR_DLL + szDLL, SEVERE);
 res = -1;
 return res;
endif;

StrRemoveLastSlash (szPath);
 StrToUpper (szPathUpper, szPath);
 cbBuffer = SizeOf (NewShare);
pNewShare = &NewShare;
pNewShare->shi50_netname = szShareName;
pNewShare->shi50_type = STYPE_DISKTREE;
  pNewShare->shi50_flags = SHI50F_FULL;
  pNewShare->shi50_remark = NULL;
  pDirPathNoWide = &szPathUpper;
  pNewShare->shi50_path = pDirPathNoWide;
  pNewShare->shi50_rw_password[0] = "\x0"; // No password
  pNewShare->shi50_ro_password[0] = "\x0"; // No password

#ifdef __DEBUG__
MessageBox ("Calling SVRAPI.NetShareAdd",INFORMATION);
#endif

res = SVRAPI.NetShareAdd (NULL,50,&NewShare,cbBuffer);

if (res != NERR_Success) then
NumToStr (buff,res);
MessageBox ("NetShareAdd failed. Errorcode = " + buff,SEVERE);
res = -1;
   endif;  

UnUseDLL ( szDLL );
return res;
end;

--------------------------------------------------------------------------

The installer rollbacks and exit when i call
res = SVRAPI.NetShareAdd (NULL,50,&NewShare,cbBuffer);

same result if i try to prototype it as
prototype STDCALL LONG SVRAPI.NetShareAdd ( POINTER, LONG, POINTER, LONG );

Awaiting for your tips,
Valerio


Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 27 August 2001 - 12:42

The short data type is two bytes long (WORD), while LONG is 4 bytes (DWORD). There is no equivalent to short in InstallScript. I suggest you build a DLL to call the WinAPI functions, and call that DLL from your script.